简体   繁体   English

WordPress类别问题

[英]WordPress Category Question

I cannot figure out how to use the wp_list_categories function to do what I need it to: 我无法弄清楚如何使用wp_list_categories函数来完成所需的操作:

<?php if(is_category() or is_page('realisations') or is_single()) { ?>
<ul id="subpage">
    <?php wp_list_categories('child_of=3&title_li=<h4>Les secteurs</h4>'); ?>
</ul>
<?php }; ?>

I have it set up so that all of the project categories are child categories of the a main category ( child_of=3 ) This is to avoid conflicts with the news section of the site. 我进行了设置,以便所有项目类别都是主要类别的子类别( child_of=3 ),这是为了避免与网站的新闻部分冲突。

The problem is that I need the category the post is in to highlight when viewing the single.php page template, but I don't know how to accomplish that. 问题是,在查看single.php页面模板时,我需要帖子所属的类别突出显示,但是我不知道该如何完成。 When on a category page the category view highlights correctly because I styled the class that WordPress adds into the generated list .current-cat . 在类别页面上时,类别视图正确突出显示,因为我设置了WordPress添加到生成的列表.current-cat的类的样式。

I answered my own question! 我回答了我自己的问题! This wonderful plugin has the function that I didn't need to write myself: http://www.screenshine.net/blog/1474_wordpress-plugin-show-active-category 这个出色的插件具有我不需要自己编写的功能: http : //www.screenshine.net/blog/1474_wordpress-plugin-show-active-category

It sets a filter to add into the wp_list_categories() function, the only thing I dislike about it is that it sets a css class on the anchor instead of the list item, which is inconsistent with WordPress functionality. 它设置了一个过滤器以添加到wp_list_categories()函数中,我对此唯一不满意的是它在锚点而不是列表项上设置了CSS类,这与WordPress的功能不一致。 It works in a pinch though, which is what I am in. You can stick it in your functions.php to prepackage the plugin and do minor edits. 不过,它在一定程度上起作用,这就是我所要解决的问题。您可以将其粘贴在functions.php中,以对插件进行预打包并进行较小的编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM