【发布时间】:2016-11-20 20:27:26
【问题描述】:
我在 WordPress 中创建了一个短代码,用于调用最新的博客文章。
我已经用<h2> 和<p> 包装了标题和内容,但这没有被应用。正在生成 html,但没有我想要的标签。我写错了什么?
这是我的代码:
<?php
//blog posts shortcode
function my_recent_post()
{
global $post;
$html = "";
$my_query = new WP_Query( array(
'post_type' => 'post',
'cat' => '4',
'posts_per_page' => 1
));
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
$html .= "<span>" . the_post_thumbnail( 'medium', array( 'class' => 'img-responsive') ) . "</span>";
$html .= "<h2>" . the_title() . "</h2>";
$html .= "<p>" . the_excerpt() . "</p>";
endwhile; endif;
return $html;
}
add_shortcode( 'blog', 'my_recent_post' );
?>
【问题讨论】: