显示1个帖子从一个特定的catergory如果在wordpress中选择
问题描述:
我想在wordpress中从1个类别拉1个帖子,但如果不是它应该显示自定义帖子类型I打电话。例如推荐书,最新消息,案例研究。显示1个帖子从一个特定的catergory如果在wordpress中选择
这是我的,我需要一个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; ?>
答
如果我理解正确:
$query->post_count
应该让你检查是否存在由查询返回的任何职位,如果没有,比你可以调用另一个查询。
请再次写一遍你想做什么。 – 2013-04-23 20:11:23