我是 Joomla 的新手,我正在研究 EasyBlog 组件,我想创建一个类别列表作为菜单并将一个类添加到当前活动的菜单项。为此,我必须连接到数据库并使用获取类别 ID$db = JFactory::getDBO();
我的问题是,可以$db = JFactory::getDBO();
在我网站的 index.php 模板上使用来获取 ID 吗?
这是我当前的脚本。
$view = JRequest::getCmd('view');
$temp = JRequest::getString('id');
if ($view == 'entry' or $view == 'tags' or $view == 'archive' or $view == 'blogger' or $view == 'teamblog') {
$db = JFactory::getDBO();
$option = JRequest::getCmd('option');
$temp = explode(':', $temp);
$id = $temp[0];
if ($option == 'com_easyblog' && $view == 'entry' && $id)
{ $db->setQuery('SELECT category_id FROM #__easyblog_post WHERE id='.$id);
$category_id = $db->loadResult(); //this is current article’s category ID
}
//echo $category_id; //show it
$cat_id = $category_id;
}
else{
$cat_id = $temp;
}