【问题标题】:Display custom taxonomy in a list using the_term_list() in WordPress在 WordPress 中使用 the_term_list() 在列表中显示自定义分类
【发布时间】:2016-08-10 20:06:10
【问题描述】:

我需要帮助来使用 the_term_list() 在 ul 中显示我的自定义分类法。

我可以让它列出我想要的所有术语,但我需要将它们放在一个无序列表中,而不仅仅是一个由 cmets 分隔的链接列表。

这是我必须处理的:

<?php echo get_the_term_list($post->ID, 'skills', '<h5>Project Role</h5> ', ', ', '', ); ?>

这里是 WordPress 函数参考,如果需要的话:http://codex.wordpress.org/Function_Reference/get_the_term_list

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    这应该让您的自定义分类显示在一个无序列表中,并且您的 h5 标题在顶部:

    <?php echo get_the_term_list( $post->ID, 'skills', '<h5>Project Role</h5><ul><li>', '</li><li>', '</li></ul>' ); ?>
    

    【讨论】:

      【解决方案2】:
      //    Use this code
          <?php
          $taxonomy     = 'product-category';
          $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        = '';
          $empty        = 1;      // 1 for yes, 0 for no
      
          $args = array(
              'taxonomy'=> $taxonomy, 'orderby' => $orderby,  'show_count' => $show_count, 'pad_counts'   => $pad_counts, 'hierarchical' => $hierarchical,
              'title_li'     => $title, 'hide_empty'   => $empty ); ?>
              <ul class="sidebar_cat" data-role="listview"> <?php $variable = wp_list_categories( $args ); $variable = str_replace(array('(',')'), '', $variable);    $variable = str_replace('(', '<span class="ui-li-count">', $variable);
              $variable = str_replace(')', '</span>', $variable);   echo $variable; ?>
              </ul>
      

      【讨论】:

        猜你喜欢
        • 2014-11-22
        • 1970-01-01
        • 2019-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-19
        • 1970-01-01
        相关资源
        最近更新 更多