WordPress的wp_list_categories

发布于 2024-10-14 14:04:07 字数 1782 浏览 7 评论 0原文

我正在使用 wp_list_categories 像这样:

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

效果很好。它输出如下:

   <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

提前致谢。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独患者 2024-10-21 14:04:07

我快速浏览了 wp_list_categories api,但我认为默认情况下你不能从 wp_list_categories 获取相对路径。

像这样的事情可能是一种解决方法,(未经测试)

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

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);
ob_start();
wp_list_categories( $args );
$html = ob_get_clean();
echo str_replace(get_bloginfo('wpurl'),'',$html);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文