我正在尝试在 wordpress 中创建一个循环,在选择时从 1 个类别中提取 1 个帖子,但如果不是,它应该显示我正在调用的自定义帖子类型的最新帖子。例如推荐、最新消息、案例研究。
这就是我所拥有的,我需要一个ifelse吗?查询猫是否不存在的语句,然后显示该 CPT 中的最新帖子。
这是我的代码。
<?php
$query = new WP_Query('post_type=testimonial&catergory_name=home&showposts=1&paged=' . $paged);
$postcount = 0;
?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<?php $postcount++; ?>
<li>
<A HREF="<?php the_permalink(); ?>"></A>
<a href="<?php the_permalink(); ?>">
<?php
if (has_post_thumbnail()) {
// check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('thumb-casestudy');
}else {
?>
<img src="<?php bloginfo('template_url'); ?>/assets/images/default.jpg" alt="<?php the_title(); ?>"/>
<?php } ?>
</a>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<p class="hm_text"><?php
//the_excerpt();
echo get_post_meta($query->post->ID, 'wpld_cf_home_page_text', true)
?></p>
</li>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>