此时,您正在查询中使用查询。因此,您需要定义global $post
在函数文件的顶部,这样它就可以分配一些内容the_post()
. 现在你有了$post
对象可以替换所有测试代码$post->attribute
:
//Recent post shortcode single
function mfbs_recent_post1x1($atts){
global $post;
$q = new WP_Query(
array( \'orderby\' => \'date\', \'posts_per_page\' => \'4\')
);
$list = \'<div class="row mfbs1x1">\';
while($q->have_posts()) : $q->the_post();
$title = $post->post_title;
$list .= \'<div class="small-12 medium-12 large-12 columns">\';
$list .= $title;
$list .= \'<a href="\' . get_permalink() . \'">\' ;
$list .= get_the_post_thumbnail($post->ID , \'medium\', array( \'class\' => \'alignleft\' ) );
$list .= \'<br>\' . get_the_title() . \'</a>\' . \'<br>\' . get_the_excerpt() . \'</div>\';
endwhile;
wp_reset_query();
return $list . \'</div>\';
}
add_shortcode(\'foodrecentpost1x1\', \'mfbs_recent_post1x1\');