gpt4 book ai didi

wordpress - 在wp_list_categories中突出显示'All'类别

转载 作者:行者123 更新时间:2023-12-02 04:06:05 26 4
gpt4 key购买 nike

我在wp_list_categories函数中给出了以下参数。

<?php wp_list_categories('show_option_all=All&hide_empty=0&title_li=&current_category=All'); ?>

我希望“所有”选项在任何类别列表中可见。但是,由于默认情况下,所有帖子均会加载,因此current_category的样式也应适用于“全部”。但是,由于All没有类别ID,因此我不知道如何将current-cat类应用于'All'。

有什么建议么?

最佳答案

您可以将列表提取到变量中(将echo = 0添加到参数中),然后使用字符串替换插入自定义类。

更新:

像这样:

<?php 
function str_replace_once($needle , $replace , $haystack){
$pos = strpos($haystack, $needle);
if ($pos === false) {
return $haystack;
}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}
$args = array( 'show_option_all' => 'All',
'hide_empty' => '0',
'title_li' => '',
'current_category' => 'All',
'echo' => '0');
$str = wp_list_categories($args);

$str = str_replace_once('<li>', '<li class="current-cat">', $str);
echo $str;
?>

关于wordpress - 在wp_list_categories中突出显示'All'类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7509826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com