【问题标题】:Loop for custom post types filtered by a taxonomy in url循环用于通过 url 中的分类过滤的自定义帖子类型
【发布时间】:2012-02-15 22:06:48
【问题描述】:

我已经创建了一个自定义帖子类型和一个自定义分类来配合它。

我不知道如何对taxonomy-{taxonomy}.php 模板上的循环进行编程,使其仅显示与某人所在的当前分类存档页面相对应的帖子。 <domain>taxonomy/term

我创建了一个基于分类进行过滤的循环,但是,它不是动态的,该循环适用于我对其编程的自定义分类的任何术语。

我希望有一种方法让它知道用户正在使用哪个分类存档(基于 url?),并且只显示来自该分类的帖子,而无需为每个分类术语创建模板。

当前循环:

<?php
  $args = array( 'post_type' => 'event', 'type' => 'party', 'post_status' => 'future', 'posts_per_page' => 50, 'order' => 'ASC' );
  $loop = new WP_Query( $args );
  while ( $loop->have_posts() ) : $loop->the_post();?>
  <div class="event-item">
    <div class="event-meta gold">
      <div class="event-date"><?php the_time('M d'); ?></div>
      <div class="event-time"><?php the_time('g:i A'); ?></div>
    </div>
    <div class="event-title">
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
          <?php the_title(); ?>
      </a>
    </div>
<div class="entrytext">
    <?php the_content(); ?>
</div>
  </div>
<?php endwhile; ?>

总结:将聚会替换为可以根据用户所在页面进行更改的东西会很壮观!

【问题讨论】:

    标签: wordpress-theming custom-post-type wordpress custom-taxonomy


    【解决方案1】:

    尝试使用get_query_var('tag'),其中“tag”是您的自定义分类的名称,并将该查询的结果添加到您的 $args。

    我用它来创建一个标签存档页面,该页面会根据我当前所在的标签更改显示。

    【讨论】:

      猜你喜欢
      • 2020-11-17
      • 1970-01-01
      • 2023-04-10
      • 2019-11-24
      • 2014-10-22
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多