开发者

wordpress wp_list_categories

i'm using wp_list_categories like so:

<?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>

which works great. it outputs as follows:

   <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/ne开发者_开发问答ws_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>

problem is i don't want an absolute path, just a relative one...

i need the href to read as /news_cat/cat-1

thanks in advance.


I took a quick look at wp_list_categories api, but I dont think you can get relative path from wp_list_categories by default.

Something like this might be a work around, (not tested)

$variable = wp_list_categories('$args');
$variable = str_replace('http://hhh.wp', '', $variable);
echo $variable;


ob_start();
wp_list_categories( $args );
$html = ob_get_clean();
echo str_replace(get_bloginfo('wpurl'),'',$html);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜