1
我對此有點新意,但我試圖創建一個wordpress函數來顯示頁面上最新4篇文章的片段短代碼。這個想法是有4個面板,每個面板顯示帖子標題,特色圖片和摘錄。我可以讓所有這些元素出現在頁面上。但是,圖像總是插入到其餘內容的上方。該函數的代碼是:當在Wordpress中使用the_post_thumbnail()時,精選圖像的位置不正確
function recent_posts_function($atts){
extract(shortcode_atts(array(
'posts' => 1,
), $atts));
$return_string = '<h2>Recent Projects</h2><div>';
query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'showposts' => $posts));
if (have_posts()) :
while (have_posts()) : the_post();
$return_string .= '<div class="portfolio-posts"><h4><a href="'.get_permalink().'">'.get_the_title().'</a></h4>'.get_the_excerpt().'<a href="'.get_permalink().'" title="'.get_the_title().'">'.the_post_thumbnail('medium').'</a></div>';
endwhile;
endif;
$return_string .= '</div>';
wp_reset_query();
return $return_string;
}
這retuns代碼首先放置圖片和內容的其餘部分這樣的:
<div class="entry-content">
<img src="http://URL.com/image1.jpg" class="attachment-medium wp-post-image" alt="alt text 1">
<img src="http://URL.com/image2.jpg" class="attachment-medium wp-post-image" alt="alt text 2">
<h2>Recent Posts</h2>
<div>
<div class="portfolio-posts">
<h4><a href="http://www.URL.com/category/post-title-1/">Post Title 1</a></h4>
<p class="lead">excerpt text from post goes here</p>
<p class="more-link-p"><a class="btn btn-danger" href="http://www.URL.com/category/post-title-1/">Read more →</a></p>
<a href="http://www.URL.com/category/post-title-1/" title="Post Title 1"></a>
</div>
<div class="portfolio-posts">
<h4><a href="http://www.URL.com/category/post-title-2/">Post Title 2</a></h4>
<p class="lead">excerpt text from post 2 goes here</p>
<p class="more-link-p"><a class="btn btn-danger" href="http://www.URL.com/category/post-title-2/">Read more →</a></p>
<a href="http://www.URL.com/category/post-title-2/" title="Post Title 2"></a>
</div>
</div>
</div>
問題是怎樣才能得到要顯示的圖像在標題下方和摘錄文本之前?任何幫助將非常感謝!
謝謝......
是的,幾乎每個以「the」開頭的WordPress函數都是如此 - 它會在被調用時回顯內容。 –
真實,很好的說明! – zillaofthegods
現貨,如果我使用get_the_post_thumbnail(null,'medium'),它會起作用。謝謝您的幫助 –