How to get Joomla K2 item as object on category page?

爱⌒轻易说出口 提交于 2019-12-11 02:57:26

问题


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;
}

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


回答1:


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


来源:https://stackoverflow.com/questions/26295729/how-to-get-joomla-k2-item-as-object-on-category-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!