繁体   English   中英

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

[英]Display posts from a Wordpress custom post type category

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

我正在尝试仅显示“客户证明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
$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;
}

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM