我写了一个短代码,当我写文章时,它会在我的网站主页上显示“x”个帖子[blog posts_per_page-"3"]
. 这是:
function getBlogPosts($atts) {
extract(shortcode_atts(array(
"posts_per_page" => \'\',
), $atts));
$queryArgs = array(
"posts_per_page" => $posts_per_page
);
$queryPosts = new WP_Query($queryArgs);
$output = "";
$output .= "<ul class=\'articles-list clearfix\'>";
if ( $queryPosts->have_posts() ) : while ( $queryPosts->have_posts() ) : $queryPosts->the_post();
$output .= "<li class=\'clearfix ind-article\'>
<a class=\'article-container\' href=\'". get_the_permalink() ."\'>";
if (has_post_thumbnail($post->ID)) {
$output .= get_the_post_thumbnail($post->ID, \'medium\'); // medium img size = 300x300. => make sure photos uploaded are at least 600x600
}
$output .= "<div class=\'article-content\'>";
$output .= "<h3 class=\'entry-title gamma uppercase\'>". get_the_title() ."</h3>";
$output .= "<span class=\'entry-meta\'>". get_the_date(\'l jS F\') ."</span>";
$output .= "</div></a></li>";
endwhile; endif;
$output .= "</ul>";
return $output;
} add_shortcode(\'blog\', \'getBlogPosts\');
然而,当我这样做的时候,博客帖子的评论表单也会显示出来(这肯定是帖子的评论表单,而不是页面-我想最后显示的博客帖子似乎只有一个评论表单)。我希望启用注释,但在使用快捷码时从中删除注释。我该怎么做?