我已经为这个问题摸不着头脑一两天了。我正在尝试让 WordPress 使用调用functions.php. 我设法使代码正常工作,但它打印到页面顶部,因为我认为echo默认情况下是 PHP ,而我需要这样做return。另一个问题是,目前它只打印单个最新结果。在我开始使用之前,循环就可以工作,HEREDOC但我想我需要使用它来返回而不是 echo。
代码:
add_shortcode('recentvideos' , 'printrecenttv');
function printrecenttv(){
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 4, // Number of recent posts thumbnails to display
'post_status' => 'publish', // Show only the published posts
'post_type' => "tv" //Show only Videos
));
foreach($recent_posts as $post) :
$perm = get_permalink($post['ID']);
$imgurl = get_the_post_thumbnail_url($post['ID'], 'full');
return <<<HTML
<div class="videoposter">
<a class="posterlink" href="$perm">
<img class="posterimg" src="$imgurl">
</a>
</div>
HTML;
endforeach; wp_reset_query();
}
我究竟做错了什么?
炎炎设计