Keyword

Show extrafield in generic.php on category overvie

  • Wouter
  • Wouter's Avatar Topic Author
  • Offline
  • New Member
More
11 years 10 months ago #107617 by Wouter
Hello,

We are developing a website based on k2. For this we make use of the extrafields to give an article an specific css class.

But when we use the archive extension this class is not applied and we get an error.

This is the error we get

Warning: Invalid argument supplied for foreach() in /home/recall/domains/domain.com/public_html/templates/mytemplate/html/com_k2/generic.php on line 19


Below you will see the code
<!-- START: Call to prepare extra fields -->
<?php  
//convertArray to use ids as key
$extrafields = array();
foreach($this->item->extra_fields as $item)
{    
$extrafields[$item->id] = $item->value;
}   
?>    
<!-- END: Call to prepare extra fields -->

<!-- Start K2 Generic (search/date) Layout -->
<div id="k2Container" class="genericView<?php echo $this->escape($this->params->get('page-id')); ?> nieuwsarchief">

        <?php if($this->params->get('genericFeedIcon',1)): ?>
        <!-- RSS feed icon -->
        <ul class="k2SendReceiveNews">
                <li class="legende_bestuur"><span>Bestuur</span></li>
                <li class="legende_regio"><span>Regio</span></li>
                <li class="legende_school"><span>School</span></li>
                <li><a href="#">Nieuws melden</a></li>
                <li><a href="#">Nieuws via e-mail ontvangen</a></li>
                <li class="rssfeed"><a href="<?php echo $this->feed; ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_RSS'); ?>">
                        <span><?php echo JText::_('K2_SUBSCRIBE_TO_RSS'); ?></span>
                </a></li>
                <div class="clr"></div>
        </ul>
        <?php endif; ?>
        
        <?php if($this->params->get('show_page_title')): ?>
        <!-- Page title -->
        <div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
                <?php echo $this->escape($this->params->get('page_title')); ?>
        </div>
        <?php endif; ?>

        <?php if(count($this->items)): ?>
        <div>
                <?php foreach($this->items as $item): ?>

                <!-- Start K2 Item Layout -->
                <div class="CatItem-<?php echo $extraFlds['Nieuwscategorie']; ?>">
                <?php
echo $item->extra_fields[11]->value;
?>

                        <div class="catItemContent catItemHeader">
                        
                          <?php if($this->params->get('genericItemTitle')): ?>
                          <!-- Item title -->
                          <h3 class="catItemTitle">
                                <?php if ($this->params->get('genericItemTitleLinked')): ?>
                                        <a href="<?php echo $item->link; ?>">
                                        <?php echo $item->title; ?>
                                </a>
                                <?php else: ?>
                                <?php echo $item->title; ?>
                                <?php endif; ?>
                          </h3>
                          <?php endif; ?>
                          <?php if($this->params->get('genericItemDateCreated')): ?>
                                <!-- Date created -->
                                <span class="genericItemDateCreated">
                                        <?php echo JHTML::_('date', $item->created , JText::_('DATE_FORMAT_LC10')); ?>
                                </span>
                                <?php endif; ?>
                  </div>

                </div>
                <!-- End K2 Item Layout -->
                
                <?php endforeach; ?>
        </div>

        <!-- Pagination -->
        <?php if($this->pagination->getPagesLinks()): ?>
        <div class="k2Pagination">
                <?php echo $this->pagination->getPagesLinks(); ?>
                <div class="clr"></div>
                <?php echo $this->pagination->getPagesCounter(); ?>
        </div>
        <?php endif; ?>

        <?php endif; ?>
        
</div>
<!-- End K2 Generic (search/date) Layout -->

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

More
11 years 10 months ago - 11 years 10 months ago #107618 by Kelsey Brookes
Replied by Kelsey Brookes on topic Re: Show extrafield in generic.php on category overvie
I think you can get around all of that by using the new extra fields capabilities in 2.6.2
Log in  or Create an account to join the conversation.

More
11 years 9 months ago #107619 by esedic
I'm almost certain that code, which was introduced in K2 v2.6 for displaying individual extra fields, doesn't work in generic.php.

Maybe I'm wrong, but I've done couple of test and I couldn't call individual extra fields from generic.php.

In template files you can call extra fields with $this->item->extra_fields.
In generic.php extra field object is accessed through $item->extra_fields.

So i tried
<?php echo $this->item->extraFields->extrafieldalias->name; ?>
<?php echo $this->item->extraFields->extrafieldalias->value; ?>

and
<?php echo $item->extraFields->extrafieldalias->name; ?>
<?php echo $item->extraFields->extrafieldalias->value; ?>

In both cases extra fields didn't show up.

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