Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display multiple galleries all at once.

something kind of like this

[gallery id=234,352,832]

The images will be sorted by most recent uploaded shown first.

Is that type of thing possible?

I'd love to do it without a plugin if possible.

share|improve this question
    
"I'd love to do it without a plugin" why? –  chrisguitarguy Dec 18 '11 at 7:52
    
I had a ton of plugins a while back and they really started to slow down the site so i'm trying to limit the amount I use to a minimum. –  Talon Dec 18 '11 at 19:37
add comment

1 Answer

up vote 1 down vote accepted

The built in [gallery] shortcode doesn't support that out of the box. However, it's pretty easy to roll your own "multi-gallery" shortcode like so:

<?php
add_action( 'init', 'wpse36779_add_shortcode' );
/**
 * Adds the shortcode
 * 
 * @ uses add_shortcode
 */
function wpse36779_add_shortcode()
{
    add_shortcode( 'multigallery', 'wpse36779_shortcode_cb' );
}

/**
 * The shortcode callback function
 *
 * @ uses do_shortcode
 */
function wpse36779_shortcode_cb( $atts )
{
    $atts = shortcode_atts(
        array(
            'id' => false
        ),
        $atts 
    );

    if( ! $atts['id'] )
    {   
        // no list of ids? Just send back a gallery
        return do_shortcode( '[gallery]' );
    }
    else
    {
        $ids = array_map( 'trim', explode( ',', $atts['id'] ) );
        $out = '';
        foreach( $ids as $id )
        {
            if( $id )
                $out .= do_shortcode( sprintf( '[gallery id="%s"]', absint( $id ) ) );
        }
    }
    return $out;
}

And of course, despite your best efforts to not use a plugin, here is that mess as a plugin. You could drop that code, minus the plugin header, in your theme's functions.php file if you really really really don't want to use a plugin.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.