如何输出带有额外标记的wp_list_categories [英] How to output wp_list_categories with extra markup
本文介绍了如何输出带有额外标记的wp_list_categories的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用以下脚本将我所有的wordpress类别输出到无序列表中.如何获得带有额外标记的输出?
I'm currently using the below script to output all my wordpress categories in an unordered list. How can I have the output with extra markup?
<ul><?php wp_list_categories('title_li&show_count=1');?></ul>
例如:
<ul>
<li>Category 1 ›</li>
<li>Category 2 ›</li>
</ul>
代替
<ul>
<li>Category 1</li>
<li>Category 2</li>
</ul>
在Obmerk Kronen的帮助下将其更改为以下内容:
Changed it to the following with the help of Obmerk Kronen:
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'number' => 20, // how many categories
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>›</li>';
}
推荐答案
有两种方法可以轻松实现.
There are two ways you can easily do it .
1-使用 get_categories()
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'number' => 20 // how many categories
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>›';
}
2-使用具有相同代码的css :after
选择器如您在问题中所张贴的
2 - use the css :after
selector with the same code as you have posted in your question
.my_class li:after{ content:" \203A";}
在此处
这篇关于如何输出带有额外标记的wp_list_categories的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文