Question

Here's what I'm trying to do:

I want to add some custom code so that when the featured items (which I have set to display first) have a title ex: 'Featured items'

AND

When they aren't featured I want the other (non-featured) items to have a different title ex: 'Non featured items'

So basically I'm trying achieve this by adding an if statement just before the itemListhead. The problem is I'm not sure what the correct php functions to call ? Here's what I've tried, but that do not work:

if ($item->featured)
if ($this->leading->item->featured)
if($params->get('FeaturedItems'))
if($this->leading->params->get->featured)

So, does anybody know how I can find out if an item is featured from the category page?

Was it helpful?

Solution

Ok, I fugured it out.

Here's the solution:

Change the following code in the itemListLeading div foreach loop in the category.php around line 152.

<?php
   // Load category_item.php by default
 $this->item=$item;
   echo $this->loadTemplate('item');?>

With this code:

<?php 
             // Load category_item.php by default
             $this->item=$item; 
?>
 <?php  if($item->featured == 1): ?>
           <?php  $x++; ?>
            <?php  if($key == 0): ?>
                      <div class="itemListHead">
                          <h2><?php echo JText::_('K2_ITEM_LIST_HEAD_FEATURED'); ?></h2>
                      </div>
             <?php endif; ?>
  <?php elseif($item->featured == 0): ?>
           <?php  if($key == $x): ?>
                       <div class="itemListHead">
                          <h2><?php echo JText::_('K2_ITEM_LIST_HEAD'); ?></h2>
                       </div>
            <?php endif; ?>
    <?php endif; ?>
    <?php echo $this->loadTemplate('item'); ?>

Of course, you will have to add K2_ITEM_LIST_HEAD_FEATURED & K2_ITEM_LIST_HEAD to your language overrrides.

It even works with pagination too !

So there it is, hope someone finds this usefull.

Peace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top