Joomla! - 改变分类页面中文章的默认呈现方式
什么状况呢?简单的说,就是Joomla!中“某category下的文章”页面默认会以标题列表的方式显示,而根据需求需要修改其默认呈现方式为日志列表(blog list)。下面为实际问题描述:
“今天在为本站增加Projects时遇到个问题;其实早该留意到,但是从来没从自身需求出发,一直忽视掉了:本站主导航中的Projects指向名为"Projects"的section,Projects首页中分类(category)列表里的"ChkVersion"指向该分类下的日志,而二级导航中的"ChkVersion"是我自己为Projects菜单项创建的item,同样指向该分类下的日志。自己创建的菜单item可以手动选择呈现方式为"日志",但Projects首页中的"ChkVersion"点击进入后系统却默认按照文章标题列表显示了。”
在Joomla! Official Documentation中找到相关的一篇文章"Make a Section Menu Item drill into a Category Blog layout"即是讲解该问题的解决方法。里面共给出三种解决方式:
- Override the rhuk_milkyway Template
虽然标题是这样,但是应该可以理解为修改当前使用的模板;详情可以参照原文,思路即是更改com_content/category中的文件名,如:blog.php → default.php,blog_item.php → default_item.php,blog_links.php → default_links.php。这样系统在调用default时便会将原来的blog_item文件认作默认,实现默认以日志方式显示文章。缺点是站内所有这样的某分类下文章页面均会已日志方式显示,title list no more了;当然如果是修改自己的站点而非写模板共用的话倒也无妨;自行判断。 - Create a Copy of rhuk_milkyway
可以理解为创建当前模板的副本,按照前面一种方法修改category中的相关文件,然后在模板管理中进入这个副本模板,选取需要修改为日志呈现方式的页面。相当于为这些页面单独使用另外一个模板而已,相比第一种方法,不会发生一刀切title list no more的状况了。个人比较推荐,虽然自己用的是第三种方法。 - Add a parameter to the View
作者特意提到“Note: The following is a "core hack", meaning that one of the Joomla! core files is modified. This means that this file could get overwritten during a Joomla! upgrade. If you make this change, be sure to keep a backup of the modified file or of the modified code. That way you can re-apply this change if it gets overwritten.”
当然就是要修改核心文件,而非override方式了,这点需注意。个人选用这种方式,一是因为自己的站点,做好规划和备忘就OK;二是我比较喜欢增设参数这种方式,可控性强些。详情仍可查看原文更加靠谱,主要思路是为\components\com_content\views\section\tmpl\default.xml 文件添加参数设置:
<param name="category_layout" type="list" default="list" label="Category Layout" description="PARAMSCATEGORYLAYOUT">
<option value="default">Default</option>
<option value="blog">Blog Layout</option>
</param>
然后修改\components\com_content\views\section\view.html.php文件,将
$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout=default');
替换为
$layout = $params->get('category_layout') ;$category->link = JRoute::_(ContentHelperRoute::getCategoryRoute($category->slug, $category->section).'&layout='.$layout);
这样在管理后台创建新的类型为section layout页面时,会发现侧边栏参数设置中多了一项设置该section下分类页面呈现方式的列表,可自行选择title list或blog list了。
最后得到的理想状况就是http://viiiix.com/projects/chkversion了。
| < Prev | Next > |
|---|
