2014-12-09 31 views
-2

請我需要找到一個解決方案,爲此幻燈片添加標題,我嘗試發佈id的拇指,但它顯示了特色圖片的標題,我需要圖片的標題我需要在wordpress上添加這個幻燈片的標題

<?php 
             global $wpdb, $post; 

             $meta = get_post_meta($post->ID, 'lioit_slideshow_imgs', false); 
             if (!is_array($meta)) $meta = (array) $meta; 
             if (!empty($meta)) { 
             $meta = implode(',', $meta); 
             $images = $wpdb->get_col(" 
             SELECT ID FROM $wpdb->posts 
             WHERE post_type = 'attachment' 
             AND ID in ($meta) 
             ORDER BY menu_order ASC LIMIT 15 
             "); 

             foreach ($images as $att) { 
             // get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes 
             $src = wp_get_attachment_image_src($att, 'full'); 
             $src = $src[0]; 

             ?> 
           <img src="<?php echo $src; ?>" alt="" > 



           <?php } 
             } ?> 
+0

我從來沒有聽說過的 「lioit滑塊」。您應該提供代碼,以便我可以檢查標題是否保存在數據庫中。如果它未保存在數據庫中,則無法檢索它。也考慮使用WP Meta Slider(https://wordpress.org/plugins/ml-slider/)。它支持多個滑塊庫,並且可以完全自定義。 – 2014-12-09 12:24:10

回答

0

如果你想獲取「替代文本」,「圖像標題」等WordPress的圖像本地字段,然後將下面的代碼:幻燈片

幻燈片的代碼是R會幫助你。

如果您想要從數據庫中檢索「自定義字段」,那麼有一種不同的方法,您需要提供有關您所使用的插件的更多詳細信息。

代碼:

<?php 
global $wpdb, $post; 

$meta = get_post_meta($post->ID, 'lioit_slideshow_imgs', false); 
if(!is_array($meta)) $meta = (array) $meta; 
if(!empty($meta)){ 
    $meta = implode(',', $meta); 
    $images = $wpdb->get_col(" 
     SELECT ID FROM $wpdb->posts 
     WHERE post_type = 'attachment' 
     AND ID in ($meta) 
     ORDER BY menu_order ASC LIMIT 15 
    "); 
    foreach($images as $att){ 
     // get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes 
     $src = wp_get_attachment_image_src($att, 'full'); 
     $src = $src[0]; 
     $alt = get_post_meta($att, '_wp_attachment_image_alt', true); 
     $image_title = $att->post_title; 
     $caption = $att->post_excerpt; 
     $description = $att->post_content; 
     echo '<img src="' . $src . '" alt="' . $alt . '" />'; 
    } 
} 
?> 
+0

它不顯示其他任何東西,只有圖像。 – gpweb 2014-12-09 12:56:06

+0

是的,因爲你需要在屏幕上顯示「$標題」,「$ description」,「$ alt」,「$ image_title」或「$ description」。你可以使用'

'。你必須自己定位元素。這超出了這個問題的範圍。 – 2014-12-09 13:01:16

+0

我試過了,但是顯示了帖子精選圖片的標題 – gpweb 2014-12-10 13:25:20