繁体   English   中英

页面开头显示的Wordpress post_thumbnail

[英]Wordpress post_thumbnail showing at the beginning of the page

我试图显示一些带有我创建的插件的帖子缩略图,但是当我将代码添加到页面时,它会在页面开始处显示缩略图,而先于其他内容显示。 我不知道为什么。

插件:

<?php
add_image_size( 'cortar', 250, 250, true ); // Hard Crop Mode
function wpb_recent_post() { 
$the_query = new WP_Query( 'showposts=1&cat=25' ); 
while ($the_query -> have_posts()) : $the_query -> the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), cortar, false, '' );?>
<img src="<?php echo $src[0];?>" />
<?php endwhile;
} 
add_shortcode('posts_recientes', 'wpb_recent_post');
?>

页面内容:

<h3>Poesia</h3>

[three_columns]
[column1]

<h4>This is a heading</h4>
[posts_recientes]

[/column1]
[column2]

<h4>This is a heading</h4>
[posts_recientes]

[/column2]
[column3]

<h4>This is a heading</h4>
[posts_recientes]

[/column3]
[/three_columns]

显示方式:

http://www.ixmapp.com/circulodepoesia/prueba/

它应该在缩略图之前显示标题。

任何帮助将非常感激。

WordPress在页面加载之前执行一次该功能,因此输出从一开始就发生。

尝试显完整的img-HTML-标记。

echo '<img src="'.$src[0].'" />';

谢谢eevaa。 您是正确的,WordPress在页面加载之前执行了该功能。 这就是我解决问题的方式。

<?php
add_image_size( 'cortar', 250, 250, true ); // Hard Crop Mode

function wpb_recent_post() { 
$the_query = new WP_Query( 'showposts=1&cat=25' ); 
while ($the_query -> have_posts()) : $the_query -> the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), cortar, false, '' );
endwhile;
wp_reset_postdata();
return('<img src=".$src[0]." />');
} 
add_shortcode('posts_recientes', 'wpb_recent_post');
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM