duanbei3747 2013-07-02 18:10
浏览 47
已采纳

Joomla - K2类别 - 如何检测项目是否有特色

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?

  • 写回答

1条回答 默认 最新

  • duandie0921 2013-09-06 20:01
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!