本文介绍了如何将Joomla K2项目作为类别页面上的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Templates/mytemplate/html/com_k2/default/category.php中获取特定于K2类别的所有项目作为对象.像这样:

I need to get all the items of specific K2 category as object in templates/mytemplate/html/com_k2/default/category.php. Something like:

foreach($this->category->items as $item) {
 echo $item->image;
}

但是我不知道K2组件的API.不仅要获得$ this-> leading或$ this-> primary或​​$ this-> secondary及其限制,而且要获得当前类别的所有项目

but I dont' know API of K2 component. To get not only $this->leading or $this->primary or $this->secondary with their limits but ALL the items of the current category

推荐答案

您可以通过直接查询MySQL来获得它:

You may get it with direct query to MySQL:

$catid = $this->category->id;
$db = &JFactory::getDBO();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id','title','published','ordering')))
      ->from($db->quoteName('#__k2_items'))
      ->where($db->quoteName('catid')." = ".$db->quote($catid))
      ->order($db->quoteName('ordering').'ASC');
$db->setQuery($query);
$itemList = $db->loadObjectList();
if(count($itemList) > 0) {
foreach ($itemList as $item){
if($item->published == 1) {
 echo '<img src="/media/k2/items/src/'.md5('Image'.$item->id).'.jpg" alt="'.$item->title.'" />';
} // if published
} // foreach
} // if count > 0

这篇关于如何将Joomla K2项目作为类别页面上的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 08:11