Gallery URL’s Problem

I had the requirement to get the url’s for the gallery images in an WordPress post for a custom rss feed.

A search didn’t reveal what I wanted, so I took the existing [code]

[/code] shortcode function and modified it to my requirements.

[code]add_shortcode(‘galleryurls’, ‘galleryurls_shortcode’);

function galleryurls_shortcode($attr) {
$id = $attr[‘id’];
$linkcode = $attr[‘linkcode’];
$maximg = $attr[‘maximg’];
$orderby = ‘menu_order ID’;
$attachments = get_children( array(‘post_parent’ => $id, ‘post_status’ => ‘inherit’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘order’ => ‘DESC’, ‘orderby’ => $orderby) );
if ( empty($attachments) )
return ”;
$images=array();
$output = “\n”;
$c=1;
foreach ( $attachments as $att_id => $attachment ) {
$images = wp_get_attachment_image_src($att_id, $size, false, false);
$output .= “<” .$linkcode .”>” . $images[0] . “\n”;
if (++$c > $maximg ) break;
}
return $output;
}
[/code]
I can now call my shortcode setting the postnumber and the maximum number of images to return. I have also included a link code as my requirement was for different codes for 2 separate feeds.

[code][galleryurls id=’2′ maximg=’5′ linkcode=’g:image_link’][/code]