2014-03-30 24 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>'; 
}