这就是我所拥有的。
<?php
$week = date(\'W\');
$year = date(\'Y\');
$projects_in_news = new WP_Query(
array(
\'post_type\' =>\'news\',
\'posts_per_page\' => 5,
\'orderby\' =>\'ID\',
\'order\' =>\'ASC\',
\'w\' => $week,
\'y\' => $year,
\'tax_query\' => array(
array(
\'taxonomy\' => \'project_taxo\',
\'terms\' => $post->post_name,
\'field\' => \'slug\'
)
)
)
);
// The Loop
<?php if($projects_in_news->have_posts()) : ?>
<?php while($projects_in_news->have_posts()) : $projects_in_news->the_post(); ?>
<ul class="side-list">
<li>
<a href="<?php the_permalink(); ?>">
<strong class="title"><?php the_title(); ?></strong>
<em class="date"><span><?php the_author(); ?>,</span> <?php the_time(\'d F Y\'); ?></em>
</a>
</li>
</ul>
<?php endwhile; ?>
<?php else: ?>
<p>There is no news related to this theme</p>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
这里显示的是上周与查询匹配的帖子。
是否有办法确定此循环查询是否有帖子,如果没有,是否使用不同的查询和循环?
我尝试添加以下代码来代替<p>There is no news related to this theme</p>
<?php
$theme_in_news = new WP_Query(
array(
\'post_type\' =>\'theme\',
\'posts_per_page\' => 5,
\'orderby\' =>\'ID\',
\'order\' =>\'ASC\',
)
);
?>
<?php if($theme_in_news->have_posts()) : ?>
<?php while($theme_in_news->have_posts()) : $theme_in_news->the_post(); ?>
<ul class="side-list">
<li>
<a href="<?php the_permalink(); ?>">
<strong class="title"><?php the_title(); ?></strong>
<em class="date"><span><?php the_author(); ?>,</span> <?php the_time(\'d F Y\'); ?></em>
</a>
</li>
</ul>
<?php endwhile; ?>
但它返回一个内部服务器错误。
谢谢