【发布时间】:2016-12-25 07:23:00
【问题描述】:
这是显示类别帖子。但它有一些错误。请任何人修复它。
这是我的 WordPress 简码
function my_form_shortcode($atts) {
ob_start();
$atts = shortcode_atts(
array(
'cat' => '1',
'showposts' => '5',
), $atts, 'my_form_shortcode' );
//YOUR CODE START
$recent = new WP_Query();
$query = "cat=".$atts['cat']."&showposts=".$atts['showposts'];
$recent->query( $query );
$is_first_post = true;
while( $recent->have_posts() ) : $recent->the_post(); ?>
<div class="panel-heading"><?php the_category(', '); ?></div>
<ul class="panel-grid">
<li class="ex">
<?php
if ( $is_first_post && has_post_thumbnail() ) {
the_post_thumbnail( 'image', array( 'class' => 'img-responsive' ));
$is_first_post = false;
}
?>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
</ul>
<?php endwhile;
//YOUR CODE END
return ob_get_clean();
}
add_shortcode( 'my_form_shortcode', 'my_form_shortcode' );
在此代码类别标题名称显示在所有帖子之前。但我只想在第 1 个帖子之前显示类别标题。这段代码有什么问题。请帮帮我..
【问题讨论】: