Created
December 18, 2011 07:44
-
-
Save chrisguitarguy/1492666 to your computer and use it in GitHub Desktop.
Add a "multigallery" shortcode to WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Multi Gallery | |
Author: Christopher Davis | |
Author URI: http://www.christopherguitar.net/ | |
License: GPL2 | |
*/ | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment