本文介绍了如何将 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 项目作为类别页面上的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!