簡體   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