我对此有点陌生,但我正在尝试创建一个 wordpress 函数,用于在带有简码的页面上显示最新 4 篇文章的片段。这个想法是有 4 个面板,每个面板显示帖子标题、特色图片和摘录。我可以让所有这些元素出现在页面上。但是,图像始终插入到其余内容的上方。该函数的代码是:
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;
}
重新调整的代码首先放置图像,然后是其余内容:
<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>
问题是如何让图像显示在标题下方和摘录文本之前?任何帮助将不胜感激!
谢谢...