首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress wp_list_categories

wordpress wp_list_categories
EN

Stack Overflow用户
提问于 2011-01-29 10:01:52
回答 2查看 2.2K关注 0票数 2

我是这样使用wp_list_categories的:

代码语言:javascript
复制
<?php 
            //list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)

            $taxonomy     = 'news_cat';
            $orderby      = 'name'; 
            $show_count   = 0;      // 1 for yes, 0 for no
            $pad_counts   = 0;      // 1 for yes, 0 for no
            $hierarchical = 1;      // 1 for yes, 0 for no
            $title        = '';

            $args = array(
              'taxonomy'     => $taxonomy,
              'orderby'      => $orderby,
              'show_count'   => $show_count,
              'pad_counts'   => $pad_counts,
              'hierarchical' => $hierarchical,
              'title_li'     => $title
            );
            ?>

            <ul class="categories fl">
            <?php wp_list_categories( $args ); ?>
            </ul>

效果很好。输出结果如下:

代码语言:javascript
复制
   <ul class="categories fl">
  <li class="cat-item cat-item-5">
    <a href="http://hhh.wp/news_cat/cat-1" title="View all posts filed under cat 1">cat 1</a>
  </li>
  <li class="cat-item cat-item-6">
    <a href="http://hhh.wp/news_cat/cat-2" title="View all posts filed under cat 2">cat 2</a>
  </li>
  <li class="cat-item cat-item-7">
    <a href="http://hhh.wp/news_cat/cat-3" title="View all posts filed under cat 3">cat 3</a>
  </li>
  <li class="cat-item cat-item-8">
    <a href="http://hhh.wp/news_cat/cat-4" title="View all posts filed under cat 4">cat 4</a>
  </li>
</ul>

问题是我不想要绝对路径,只想要相对路径...

我需要href读取为/news_cat/cat-1

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-03 22:15:20

代码语言:javascript
复制
ob_start();
wp_list_categories( $args );
$html = ob_get_clean();
echo str_replace(get_bloginfo('wpurl'),'',$html);
票数 1
EN

Stack Overflow用户

发布于 2011-01-29 13:34:49

我快速浏览了一下wp_list_categories应用程序接口,但我认为默认情况下不能从wp_list_categories获取相对路径。

像这样的东西可能是一个变通的方法,(未经过测试)

代码语言:javascript
复制
$variable = wp_list_categories('$args');
$variable = str_replace('http://hhh.wp', '', $variable);
echo $variable;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4834653

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档