php - 如何使用额外的标记输出 wp_list_categories

标签 php wordpress loops

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

<ul><?php wp_list_categories('title_li&show_count=1');?></ul>

例如:

<ul>
<li>Category 1 &rsaquo;</li> 
<li>Category 2 &rsaquo;</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>&rsaquo;</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>&rsaquo;';
    } 

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

.my_class li:after{ content:" \203A";}

查看其他字符以及如何使用它们here

关于php - 如何使用额外的标记输出 wp_list_categories,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20775747/

相关文章:

php - 使用 Laravel 和 MSSQL 将 nvarchar 转换为 datetime 数据类型时出错

php - Wordpress,通过名称或 URL 获取帖子内容

css - 移动设备的单列布局

css - child 主题中的子菜单问题

python - 如何将函数的每个输入参数设置为 None 并验证是否返回错误?

php - 我可以将 index.php 放在子目录中,但不在 url 中显示子目录吗?

php - 警告::无效的对象或资源 mysqli_stmt。意义和解决方案是什么?

wordpress - 从无法启动的 Ubuntu 框中恢复 Wordpress

javascript - mysql循环显示图像。需要帮助传递/设置每个图像的计数 - javascript

python - 用多索引迭代连接 Pandas 数据框