wp_list_categories 不显示当前类别

发布于 2024-08-17 07:05:17 字数 322 浏览 0 评论 0原文

我的博客的主菜单由类别组成,通过 wp_list_categories 函数显示。

如果我单击其中一个类别,则当前类别会在类别菜单中突出显示,并列出该类别内的文章列表。一切都很好。

但是,如果我单击一篇文章,“类别”菜单将不再显示当前类别。有人知道我该如何解决这个问题吗?

这是我用来在侧边栏中生成菜单的代码。

<?php
wp_list_categories('child_of=55&sort_column=menu_order&sort_order=asc&title_li=');
?>

My blog's main menu is made of the categories, displayed via the wp_list_categories function.

If i click on one of the categories, the current category is highlighted in the category menu, and the list of articles inside that category are listed. Everything is fine.

But if i then click on one article, the Category menu does not show the current category anymore. Anyone knows how i could fix that?

Here is the code i use to generate the menu in the sidebar.

<?php
wp_list_categories('child_of=55&sort_column=menu_order&sort_order=asc&title_li=');
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-08-24 07:05:17

我在 WordPress 论坛上发现了一个很好的技巧。它只会显示一个“当前”类别,但足以满足我的需求。

<?php
    if  (!is_page() && !is_home() && !is_single()){
    $catsy = get_the_category();
    $myCat = $catsy->cat_ID;
    $currentcategory = '¤t_category='.$myCat;
}

    elseif (is_single()){
    $catsy = get_the_category();
    $myCat = $catsy[0]->cat_ID;
    $currentcategory = '¤t_category='.$myCat;
}

    wp_list_categories('depth=1&title_li=&orderby=id&exclude=1,5,6,19,20,21,22&hide_empty=0'.$currentcategory);
    ?>

如果当您有一个多类别每帖子系统时仅突出显示 1 个类别,您可能需要使用 这个插件(在样式表中添加一个 .used-cat 类,以及 wordpress 提供的 .current-cat 类)。

I found a good hack on the wordpress forum. It will only show one "current" category but it's enough for my needs.

<?php
    if  (!is_page() && !is_home() && !is_single()){
    $catsy = get_the_category();
    $myCat = $catsy->cat_ID;
    $currentcategory = '¤t_category='.$myCat;
}

    elseif (is_single()){
    $catsy = get_the_category();
    $myCat = $catsy[0]->cat_ID;
    $currentcategory = '¤t_category='.$myCat;
}

    wp_list_categories('depth=1&title_li=&orderby=id&exclude=1,5,6,19,20,21,22&hide_empty=0'.$currentcategory);
    ?>

If only highlighting 1 category when you have a multi-category-per-post system, you might want to use this plugin instead (add a .used-cat class in your stylesheet, alongside the .current-cat class provided by wordpress).

乖乖 2024-08-24 07:05:17

“parent”不是 wp_list_categories 的有效参数。

另外,您确定相同的代码为类别页面和帖子页面提供类别列表吗?该代码可能位于 is_category 或 is_post/is_page 块内。

'parent' isn't a valid argument for wp_list_categories.

Also, are you sure the same code is providing the category list for both the category page and the post page? The code might be within an is_category or is_post/is_page block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文