当浏览k2文章时,激活k2的分类菜单项

讨论环境:

  • joomla 1.5
  • k2 2.41

k2的工具模块(k2 tools)具有分类菜单的功能,这个功能是比较常用的。

当我们浏览某个分类页面,对应的菜单项就会被“激活”,为其添加对应的激活css样式;但当我们浏览此分类下的某篇文章时,对应的菜单项并不会被激活。

因此我们需要修改k2 tools模块下的helper.php文件 位置:modules/mod_k2_tools/helper.php

在大约258行添加以下代码

//Joomkit active highlight tweak
//only perform if item is being viewed
if ($view == 'item'){

//get article id
$K2itemid = JRequest::getInt('id');

$query = "SELECT catid FROM #__k2_items WHERE id = {$K2itemid} AND published=1 AND trash=0 AND access<={$aid} ";
$db->setQuery($query);

//return items category id
$ItemCatid = $db->loadResult();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
}

代码上下位置关系

static $output;
if ($begin) {
$output = '';
}

$root_id = (int) $params->get('root_id');
$end_level = $params->get('end_level', NULL);
$id = (int) $id;
$catid = JRequest::getInt('id');
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');

$user = &JFactory::getUser();
$aid = (int) $user->get('aid');
$db = &JFactory::getDBO();

//Joomkit active highlight tweak
//only perform if item is being viewed
if ($view == 'item'){

//get article id
$K2itemid = JRequest::getInt('id');

$query = "SELECT catid FROM #__k2_items WHERE id = {$K2itemid} AND published=1 AND trash=0 AND access<={$aid} ";
$db->setQuery($query);
//return items category id
$ItemCatid = $db->loadResult();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
}

switch ($params->get('categoriesListOrdering')) {

case 'alpha':
$orderby = 'name';
break;

case 'ralpha':
$orderby = 'name DESC';
break;

case 'order':
$orderby = 'ordering';
break;

case 'reversedefault':
$orderby = 'id DESC';
break;

default:
$orderby = 'id ASC';
break;
}

if (($root_id != 0) && ($level == 0)) {
$query = "SELECT * FROM #__k2_categories WHERE parent={$root_id} AND published=1 AND trash=0 AND access<={$aid} ORDER BY {$orderby}";

} else {
$query = "SELECT * FROM #__k2_categories WHERE parent={$id} AND published=1 AND trash=0 AND access<={$aid} ORDER BY {$orderby}";
}

然后修改位置大概在325行(添加了上面代码的后的行数)

把原来的:

if (($option == 'com_k2') && ($view == 'itemlist') && ($catid == $row->id)){

替换成

if ( (($option == 'com_k2') && ($view == 'itemlist')  &&  ($catid == $row->id)) || (($option == 'com_k2')  && ($view ==  'item') && ($row->id == $ItemCatid)) ){

然后添加对应的css规划就行了,这里就不写了,有兴趣的朋友可以看原文:

http://community.getk2.org/profiles/blogs/active-menu-items-part-two

  • 作者:野草工作室
  • 发布日期:2011-05-03
  • 文章标签: K2教程

文章评论功能仅对网站会员开放,请先 登录 注册

栏目公告

原野草工作室官网的博客栏目的文章,会逐步迁移至Joomla建站笔记栏目。

Joomla主机