列出基于其他分类的分类术语

时间:2015-08-19 作者:Joe

我有一个自定义的帖子类型,叫做Resources.

资源post类型有两种不同的分类法,Resource TypesResource Tags.

资源类型设置资源(指南、文章、新闻稿)的格式/类型。

资源标记设置内容分类(规划、投资、退役)

在我的资源类型分类页面(taxonomy-Resource\\u types.php)上,我希望有一个与该资源类型匹配的帖子的所有资源标记的列表(和链接)。它将输出到ID为“resourceTagList”的中。这将充当此指定资源类型中使用的所有资源标记的主列表。这些将被用作网站上的过滤机制。

例如,在Articles archive页面上,我想查看在标记为文章的任何资源上设置的每个资源标记的列表。

以下是我当前在资源类型分类页面上使用的代码的相关部分:

<?php if (have_posts()) { ?>
  <div id="tagList">
    <h6>Filter by:</h6>
      <ul id="resourceTagList">
        <li><a href="">All</a></li>
        <?php //list taxonomy terms
        $terms = get_terms( \'resource_tags\' );
        foreach ( $terms as $term ) {
          // The $term is an object, so we don\'t need to specify the $taxonomy.
          $term_link = get_term_link( $term );
          // If there was an error, continue to the next term.
          if ( is_wp_error( $term_link ) ) {
            continue;
          }
          // We successfully got a link. Print it out.
          echo \'<li><a href="\' . esc_url( $term_link ) . \'">\' . $term->name . \'</a></li>\';
        } ?>
      </ul>
    </div>
  <div id="restList">
    <?php while (have_posts()) :
      the_post(); ?>
      <div class="resListing">
        <div class="resText">
          <h2><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h2>
          <?php the_excerpt(); ?>
        </div>
        <div class="resButton">
          <a href="<?php echo get_permalink(); ?>" class="blueButton">Learn More</a>
        </div>
      </div>
    <?php endwhile; ?>
  </div>   
<?php }else{ ?> 
  <h1>No Resources Found</h1>
<?php } ?>
这将为每个附加了任何帖子的资源标记输出一个链接列表,但这不会根据资源类型检查资源标记。

不幸的是,我不知道从这里到哪里去实现这一点,所以希望这里有人以前经历过这一点。

1 个回复
SO网友:Abdullah Alsigar

首先获取具有所需分类的帖子

$posts=get\\u posts(\'资源类型\'=>\'存档\')

然后循环结果并使用此函数

wp\\U get\\U post\\U条款($post\\U id)

我想你已经知道如何显示结果了

结束

相关推荐