get_children()并设置alt图像=滑块

时间:2014-03-30 18:07:17

标签: php wordpress

如何让图像将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 个答案:

答案 0 :(得分:1)

我想你是否试图将alt属性设置为&#34; slider&#34;所以试试这个

$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>'; 
}