显示<;中每个WordPress类别的链接计数;a>;标记自己
您可能知道,要在WordPress中获取类别列表,请使用:显示<;中每个WordPress类别的链接计数;a>;标记自己,wordpress,Wordpress,您可能知道,要在WordPress中获取类别列表,请使用: <ul> <?php wp_list_categories('orderby=name&show_count=1&title_li='); ?> </ul> 是否可以在不使用的情况下获取它,并在中显示每个类别的链接计数 与此不同的是: <nav> <ul> <li><a href="?cat=1">Arabesque&l
<ul>
<?php wp_list_categories('orderby=name&show_count=1&title_li='); ?>
</ul>
是否可以在不使用的情况下获取它,并在中显示每个类别的链接计数
与此不同的是:
<nav>
<ul>
<li><a href="?cat=1">Arabesque</a> (3)</li>
<li><a href="?cat=2">Business</a> (5)</li>
</ul>
</nav>
- (三)
- (五)
要在a
标记内移动post计数,请在functions.php文件中使用以下代码段:
function prefix_move_category_count( $links ) {
$links = str_replace( '</a> <span class="count">', ' <span class="count">', $links );
$links = str_replace( '</span>', '</span></a>', $links );
return $links;
}
add_filter( 'wp_list_categories', 'prefix_move_category_count' );
函数前缀\移动\类别\计数($links){
$links=str_替换(“”,,$links);
$links=str_替换(“”,,$links);
返回$links;
}
添加过滤器(“wp\U列表\U类别”,“前缀\U移动\U类别\U计数”);
来源:最好的方法是使用过滤器:
add_filter( 'wp_list_categories', 'mytheme_category_list' );
function mytheme_category_list( $list ) {
//remove ul tags
$list = str_replace( '<ul>', '', $list );
$list = str_replace( '</ul>', '', $list );
//remove li tags
$list = preg_replace( '~<li(.*?)>~s', '', $list );
$list = str_replace( '</li>', '', $list );
//move count inside a tags
$list = str_replace( '</a> (', '(', $list );
$list = str_replace( ')', ')</a>', $list );
return $list;
}
add_filter('wp_list_categories'、'myteme_categories_list');
函数mytheme\u类别\u列表($list){
//移除ul标签
$list=str_替换(“”,“$list”);
$list=str_replace(“
”,“$list”);
//删除li标签
$list=preg_replace('~~s','$list);
$list=str_replace(“
”,“$list”);
//在标签中移动计数
$list=str_replace('(','(',$list);
$list=str_替换(')',')',$list);
返回$list;
}
从GitHub获得
完美地工作
/**
*在链接内移动类别帖子计数
*
*过滤器wp_列表_类别()
*
*@param string$links链接html输出
*@返回字符串
*/
函数前缀\移动\类别\计数($links){
$links=str_替换(“”,,$links);
$links=str_替换(“”,,$links);
返回$links;
}
添加过滤器(“wp\U列表\U类别”,“前缀\U移动\U类别\U计数”)
/**
*在链接内移动存档日志计数
*
*筛选器获取\u存档\u链接()
*
*@param string$links链接html输出
*@返回字符串
*/
函数前缀\u移动\u存档\u计数($links){
$links=str_replace('(','(',$links));
$links=str_replace(')',')',$links);
返回$links;
}
添加过滤器('get_archives_link','prefix_move_archive_count') wp_list_cats Deprecate查看此更新到新函数。应添加到
functions.php
,对吗?它不起作用。请在wp config.php
中打开调试,您是否看到任何错误?谢谢,它也适用于wp\u列表页面
,但不适用于wp\u get\u归档文件
;不应该也使用此功能吗?对于存档,请使用筛选器get_archives_链接,而不是wp_get_archives
add_filter( 'wp_list_categories', 'mytheme_category_list' );
function mytheme_category_list( $list ) {
//remove ul tags
$list = str_replace( '<ul>', '', $list );
$list = str_replace( '</ul>', '', $list );
//remove li tags
$list = preg_replace( '~<li(.*?)>~s', '', $list );
$list = str_replace( '</li>', '', $list );
//move count inside a tags
$list = str_replace( '</a> (', '(', $list );
$list = str_replace( ')', ')</a>', $list );
return $list;
}
$links = str_replace( '</a> <span class="count">', ' <span class="count">', $links );
$links = str_replace( '</span>', '</span></a>', $links );
return $links;
$links = str_replace( '</a> (', ' <span class="count">(', $links );
$links = str_replace( ')', ')</span></a>', $links );
return $links;