简体   繁体   English

Joomla-K2类别-如何检测商品是否为特色

[英]Joomla - K2 Category - How to detect if item is featured

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' 我想添加一些自定义代码,以便当特色商品(我已设置为首先显示)具有标题ex时:“特色商品”

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. 所以基本上我想通过在itemListhead之前添加一个if语句来实现这一点。 The problem is I'm not sure what the correct php functions to call ? 问题是我不确定要调用什么正确的php函数? 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? 因此,有人知道我如何从类别页面中找到某项商品吗?

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. 在第152行的category.php中的itemListLeading div foreach循环中更改以下代码。

<?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. 当然,您必须将K2_ITEM_LIST_HEAD_FEATURED和K2_ITEM_LIST_HEAD添加到您的语言超限中。

It even works with pagination too ! 它甚至也可以在分页中使用!

So there it is, hope someone finds this usefull. 就是这样,希望有人能发现这一点。

Peace. 和平。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM