如何使用额外标记输出wp_list_categories

Eri*_*ric 2 php wordpress loops

我目前正在使用以下脚本在无序列表中输出我的所有wordpress类别.如何使用额外标记获得输出?

<ul><?php wp_list_categories('title_li&show_count=1');?></ul>
Run Code Online (Sandbox Code Playgroud)

例如:

<ul>
<li>Category 1 &rsaquo;</li> 
<li>Category 2 &rsaquo;</li> 
</ul>
Run Code Online (Sandbox Code Playgroud)

代替

<ul>
<li>Category 1</li> 
<li>Category 2</li> 
</ul>
Run Code Online (Sandbox Code Playgroud)

编辑:在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>&rsaquo;</li>';
    } 
Run Code Online (Sandbox Code Playgroud)

Obm*_*nen 8

有两种方法可以轻松完成.

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>&rsaquo;';
    } 
Run Code Online (Sandbox Code Playgroud)

2 - 使用与您在问题中发布的代码相同的css :after选择器

.my_class li:after{ content:" \203A";}
Run Code Online (Sandbox Code Playgroud)

请参阅其他字符以及如何在此处使用它们