【问题标题】:adding an 'all' category to my category links将“所有”类别添加到我的类别链接
【发布时间】:2015-08-11 05:49:22
【问题描述】:
我的 Wordpress 网站的索引/主页是我所有的帖子。我使用以下代码在页眉中列出页面上的所有类别。
<h3><?php wp_list_categories(); ?></h3>
这列出了我拥有的所有类别,并链接到存档页面,显示每个类别的帖子。在此页面上,我想添加并突出显示“全部”部分,因为在此页面上所有帖子都是可见的。
不知道怎么做。
【问题讨论】:
标签:
javascript
php
html
wordpress
【解决方案1】:
只需添加带有链接文本值的show_option_all 参数。见Codex: wp_list_categories。
show_option_all
(string) 当“style”设置为“list”时,设置此参数会输出到所有类别的链接。默认值为“NULL”(不显示所有类别链接)。
<?php
$args = array(
'show_option_all' => 'All posts'
);
?>
<h3><?php wp_list_categories($args); ?></h3>
“所有帖子”链接将在其 <li> 上包含 cat-item-all 类。因此,您可以轻松地使用 CSS 突出显示它。
例如:
li.cat-item-all a{
font-weight: bold;
}