lundi 2 mai 2016

How can I process multiple ids through a wordpress shortcode?

Im trying to pass multiple image ids through a wordpress shortcode, currently my wordpress shortcode is as follows:

[lemonslider images="35,46,43,42,41"]

And my function for this as follows, the idea was for each image id it would return a html image string for each of the image ids, but currently it only generates one:

// LEMON SLIDER SHORTCODE

function lemon_slider( $atts ){
$a = shortcode_atts( array(
    'images' => '44',
    'toshow' => '5',
), $atts );

$SlImages = $a['images'];
$arrlength = count($SlImages);

for($x = 0; $x < $arrlength; $x++) {
    $image_attributes = wp_get_attachment_image_src( $attachment_id = $SlImages);
    return ('<img src=' . $image_attributes[0] . ' width=' . $image_attributes[1] . ' height=' . $image_attributes[2] . ' />');

}

}
add_shortcode( 'lemonslider', 'lemon_slider' );

Ive been looking at foreach loops but Im not sure how to return multiple values.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire