2009-10-23 53 views

回答

4

原來的標題存儲爲後期摘錄。所以,

<?php echo $post->post_excerpt; ?> 

將打印出標題,如果你在附件圖像頁面(image.php在你的主題)和循環內。

15

如果您試圖在帖子中獲取標題,可以在「the_post_thumbnail」標記中將其回顯出來。

<?php the_post_thumbnail(); 
echo get_post(get_post_thumbnail_id())->post_excerpt; ?> 

您還可以使用相同的方法來顯示圖像說明。這是在WordPress 3.5

<?php the_post_thumbnail(); 
echo get_post(get_post_thumbnail_id())->post_content; ?> 

好一點的功能,如果需要樣式的標題或說明你可以用它在一個div像下面。

<?php the_post_thumbnail(); 
    echo '<div class="myDiv">' . get_post(get_post_thumbnail_id())->post_excerpt . '</div>' 
; ?> 

希望有所幫助。

0

我正在使用此代碼,它工作正常。

$get_description = get_post(get_post_thumbnail_id())->post_excerpt; if(!empty($get_description)){//If description is not empty show the div echo '<div class="img-caption">' . $get_description . '</div>'; } 
0

使用WordPress 4.8,這個小傢伙爲我工作:

<?php the_post_thumbnail_caption(); ?> 
0

把你的single.php文件的這裏面的數字標籤

$image_caption = get_post(get_post_thumbnail_id())->post_excerpt; 
if(!empty($image_caption)) { 
    echo '<figcaption itemprop="caption">' . $image_caption . '</figcaption>'; 
} 
相關問題