2014-03-30 25 views
-4

如何獲取圖像以將alt設置爲「滑塊」?get_children()並設置alt圖像=滑塊

這是我的代碼:

$args = array(
    'post_parent' => $post->ID, 
    'post_type' => 'attachment', 
    'orderby' => 'menu_order', 
    'order' => 'ASC', 
    'numberposts' => 5, 
    'post_mime_type' => 'image' 
); 
if ($images = get_children($args)) { 

echo '<div id="sliderbody" style="width:640px; height:480px;"><div id="slider">'; 

     foreach($images as $image) { 
      echo wp_get_attachment_image($image->ID, 'trueslider'); 
     } 
echo '</div></div>'; 
} 

回答

1

我想你想設置alt屬性永遠是「滑」,所以試試這個

$args = array(
    'post_parent' => $post->ID, 
    'post_type' => 'attachment', 
    'orderby' => 'menu_order', 
    'order' => 'ASC', 
    'numberposts' => 5, 
    'post_mime_type' => 'image' 
); 
if ($images = get_children($args)) { 

echo '<div id="sliderbody" style="width:640px; height:480px;"><div id="slider">'; 

     foreach($images as $image) { 
      echo wp_get_attachment_image($image->ID, 'trueslider', false, array('alt' => 'slider')); 
     } 
echo '</div></div>'; 
}