Skip to content

Instantly share code, notes, and snippets.

@beshur
Created April 11, 2012 23:16
Show Gist options
  • Save beshur/2363417 to your computer and use it in GitHub Desktop.
Save beshur/2363417 to your computer and use it in GitHub Desktop.
PHP Wordpress - slidejs simple
// easy SlidesJs gallery adding to wordpress page
function slides_from_post($atts) {
extract(shortcode_atts(array(
"exclude" => '' // parameter to exclude the images you don't want to show
), $atts));
;
$tmp = explode(", ", $exclude);
if ($tmp) {
foreach ($tmp as $tmpItem) {
$exclude_array[$tmpItem] = "exclude";
}
} else {}
$attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
if ($attachments) {
echo '<div id="slides'.get_the_ID().'" class="inline"><div class="slides_container"><ul>';
foreach ( $attachments as $attachment_id => $attachment ) {
if (!$exclude_array[$attachment_id]) {
echo '<li class="slide">'.wp_get_attachment_image( $attachment->ID, 'medium', 0 ).'</li>';
}
}
echo '</ul><div id="slides"><div class="slides_container">';
echo '
<script type="text/javacript">
jQuery("slides'.get_the_ID().'").slides();
</script>
';
}
}
add_shortcode('slides', 'slides_from_post');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment