2014-12-09 84 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