我目前正在使用以下脚本在无序列表中输出我所有的 wordpress 类别。如何获得带有额外标记的输出?
<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 的帮助下将其更改为以下内容:
$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>';
}
最佳答案
有两种方法可以轻松做到。
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
selector使用与您在问题中发布的相同代码
.my_class li:after{ content:" \203A";}
查看其他字符以及如何使用它们here
关于php - 如何使用额外的标记输出 wp_list_categories,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20775747/