Keyword

Extra Fields??? Really curious

  • Chris
  • Chris's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago - 12 years 11 months ago #58103 by Chris
Extra Fields??? Really curious was created by Chris
Hi,

I am new to both the K2 platform as well as this community. I would like to quickly say great job on this product, I heard about it for quite some time and recently just installed it, i'm very impressed.

I hope I am posting this in the right area. Since this question is regarding a function that is "Out of the Box" hopefully someone can shed some light on the matter.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I am currently setting up categories/articles on a site using K2. Below is a scenario of what I am currently working with and will hopefully and clearly explain what it is I'm in need of assistance with.

Category A (Displays custom fields for Author and Source)

- Article Item #1 ( Author Field = Chris | Source Field = website.com )
- Article Item #2 ( Author Field = Chris | Source Field = )
- Article Item #3 ( Author Field = | Source Field = website.com )
- Article Item #4 ( Author Field = | Source Field = )

In Category A, I have Extra Fields Author and Source. I am just curious, some articles within this category will sometimes have an Author and Source, while others may have either an Author OR Source and in some cases there might be NO Author / Source.

I would assume that this would work off of a IF THEN Statement to display a field value if something has been applied or display a Blank value if nothing has been applied to the fields...

Right now what happens for me is, even if no value has been applied into an articles Extra Fields for Author and/or Source, when you view the article, Author and Source still display even though the values are empty.

If the values were applied, it would look like

Author: Chris | Source: website.com

with blank values, I get this

Author: | Source:

(I don't want Author and/or Source to display if no value has been applied to those extra fields)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Here are the lines of code in the template file I am working in (this should be the right file, but if it is not, please point me in the right direction.)

/public_html/components/com_k2/templates/default/item.php
<!--BEGIN EXTRA FIELDS-->

 <?php if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)): ?>
          <!-- Item extra fields -->
          <div class="itemExtraFields">
                <h3><?php echo JText::_('Additional Info'); ?></h3>
                <ul>
                        <?php foreach ($this->item->extra_fields as $key=>$extraField):?>
                        <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
                                <span class="itemExtraFieldsLabel"><?php echo $extraField->name; ?>:</span>
                                <span class="itemExtraFieldsValue"><?php echo $extraField->value; ?></span>
                        </li>
                        <?php endforeach; ?>
                        </ul>
            <div class="clr"></div>
          </div>
          <?php endif; ?>


<!--END EXTRA FIELDS-->

Thank you very much for your time and hopefully someone can shed some light on this for me.

Chris

Seamuno - Web & Social Media Design and Development
Join us on Facebook Today
Add me on Skype: Seamuno

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #58104 by william white
Replied by william white on topic Re: Extra Fields??? Really curious
Wrap the code that echos inside the foreach loop with
if(!empty($extraField->value)) :
and endif
to suppress display of empty extra fields name and value

Please Log in or Create an account to join the conversation.

  • Chris
  • Chris's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 11 months ago #58105 by Chris
Replied by Chris on topic Re: Extra Fields??? Really curious
Hi William,

Thanks so much for your quick response, I really appreciate it. I applied the line you stated and it worked.

Thanks again, very much appreciated

Chris

Seamuno - Web & Social Media Design and Development
Join us on Facebook Today
Add me on Skype: Seamuno

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #58106 by william white
Replied by william white on topic Re: Extra Fields??? Really curious
welcome!

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum