Php 在Wordpress中使用_post_缩略图()时,特征图像的位置不正确
我在这方面有点生疏,但我正在尝试创建一个wordpress函数,用于在带有短代码的页面上显示最近4篇文章的片段。这个想法是有4个面板,每个面板显示文章标题、特色图片和摘录。我可以让所有这些元素出现在页面上。但是,图像总是插入到其余内容的上方。该功能的代码为:Php 在Wordpress中使用_post_缩略图()时,特征图像的位置不正确,php,wordpress,Php,Wordpress,我在这方面有点生疏,但我正在尝试创建一个wordpress函数,用于在带有短代码的页面上显示最近4篇文章的片段。这个想法是有4个面板,每个面板显示文章标题、特色图片和摘录。我可以让所有这些元素出现在页面上。但是,图像总是插入到其余内容的上方。该功能的代码为: function recent_posts_function($atts){ extract(shortcode_atts(array( 'posts' => 1, ), $atts)); $retu
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;
}
功能最近发布功能($atts){
提取(短码)附件(数组)(
“职位”=>1,
)美元(附件);;
$return_string='最近的项目';
查询帖子(数组('orderby'=>'date','order'=>'DESC','showposts'=>$posts));
如果(have_posts()):
while(have_posts()):the_post();
$return_string.=''。获取_摘录();
结束时;
endif;
$return_字符串='';
wp_reset_query();
return$return\u字符串;
}
此重新运行的代码将图像放在第一位,而其余内容则放在第一位:
<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>
最近的职位
这里是文章的摘录
第2篇文章摘录如下
问题是如何让图像显示在标题下方和摘录文本之前?任何帮助都将不胜感激
谢谢……所以,我记得不久前我自己也遇到过这个问题。结果是请求内容的“转储”。您需要的是可以回送或存储在变量中以供以后使用的东西 解决这个问题的办法是查看链接 这样,您就可以
echo
将其输出或存储在变量中供以后使用,而不是像某种畜牲一样将其粗暴地转储
快乐编码 是的,几乎每一个以“the”开头的WordPress函数都是这样的-调用时它会回显内容。是的,非常清楚!请注意,如果我使用get_the_post_缩略图(null,'medium'),它就可以工作。谢谢你的帮助