【问题标题】:Display posts from a Wordpress custom post type category显示来自 Wordpress 自定义帖子类型类别的帖子
【发布时间】:2015-01-20 12:05:13
【问题描述】:

我设置了一个名为 TESTIMONIALS 的自定义帖子类型,并设置了两个 CPT 类别,即 CLIENT TESTIMONALS 和 CLINIC TESTIMONIALS

我正在尝试仅显示来自 CLIENT TESTIMONALS CPT 类别的帖子。

我需要在下面添加什么来实现这一点?

 <div role="tabpanel" class="tab-pane fade" id="profile">
          <?php query_posts('post_type=testimonials'); ?>
          <?php while ( have_posts() ) : the_post(); ?>
          <div class="testimonial-holder wrap ">
            <div class="three-quarters">
              <h2>
                <?php the_title(); ?>
              </h2>
              <div class="testi">
                <?php the_content(); ?>
              </div>
            </div>
            <div class="four-col right center">
              <div class="testimonial-autor-image"> <img src="<?php the_field('author_image_or_clinic_logo'); ?>"   alt="Author Image">
                <div class="mt20">
                  <?php the_field('testimonial_author'); ?>
                </div>
              </div>
            </div>
          </div>
          <?php endwhile; // end of the loop. ?>
        </div>

【问题讨论】:

    标签: php wordpress post


    【解决方案1】:

    你可以使用这样的东西。

    <?php
    $type = 'testimonials';
    $args=array(
      'post_type' => $type,
       'category'=>'CPT',
      'post_status' => 'publish'
    );
    
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <div class="testimonial-holder wrap ">
            <div class="three-quarters">
              <h2>
                <?php the_title(); ?>
              </h2>
              <div class="testi">
                <?php the_content(); ?>
              </div>
            </div>
            <div class="four-col right center">
              <div class="testimonial-autor-image"> <img src="<?php the_field('author_image_or_clinic_logo'); ?>"   alt="Author Image">
                <div class="mt20">
                  <?php the_field('testimonial_author'); ?>
                </div>
              </div>
            </div>
          </div>
        <?php
      endwhile;
    }
    
    ?>
    

    【讨论】:

    • 谢谢,您会在哪里定义 CPT 类别?我正在将此代码添加到网站主页
    • 什么是你的两个类别蛞蝓?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 2016-12-29
    • 2020-05-11
    相关资源
    最近更新 更多