显示Wordpress自定义帖子类型类别中的帖子

时间:2015-01-20 12:05:14

标签: php wordpress post

我有一个名为TESTIMONIALS的自定义帖子类型设置和两个CPT类别设置,这些类别是CLIENT TESTIMONALS&临床证言

我正在尝试仅显示来自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>

1 个答案:

答案 0 :(得分:0)

你可以使用这样的东西。

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

?>
相关问题