在自定义taxonomy-category.php中,我不会显示该类别的所有帖子,但使用此代码,仅在该类别有+2帖子时才显示帖子 什么是不正确的?
<?php
$loop = mep_event_query(20, 'ASC', $term_id, '', '', '', 'upcoming');
if (have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();{
do_action('mep_event_list_shortcode', get_the_id(), 'four_column', 'grid');
}
wp_reset_postdata();
endwhile;
else: ?>
<p class="avis-no-cursos">En estos momentos no hay disponible ningun curso.</p>
<p class="boto-negre">
<a href="https://www.url" class="custom-link btn btn-sm border-width-0 btn-default btn-icon-right btn-ripple-out btn-border-animated cursor-init">Ver cursos disponibles<i class="fa fa-angle-right"></i></a>
</p>
<?php endif;
?>
需要进行一些语法更正,例如
have_posts()
函数检查全局 $wp_query object
,它与 mep_event_query
创建的 $loop 变量没有直接关系。所以这里是经过更正的更新代码,这应该适合你。
<?php
$loop = mep_event_query( 20, 'ASC', $term_id, '', '', '', 'upcoming' );
if ( $loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();
do_action( 'mep_event_list_shortcode', get_the_ID(), 'four_column', 'grid' );
endwhile;
wp_reset_postdata();
else: ?>
<p class="avis-no-cursos">En estos momentos no hay disponible ningun curso.</p>
<p class="boto-negre">
<a href="https://www.url" class="custom-link btn btn-sm border-width-0 btn-default btn-icon-right btn-ripple-out btn-border-animated cursor-init">Ver cursos disponibles<i class="fa fa-angle-right"></i></a>
</p>
<?php endif; ?>