Hi I wanted to change the default WordPress gallery short-code and make it a slider.
remove_shortcode( 'gallery' );
function gallery_filter( $atts, $content = null ) {
extract(shortcode_atts(array('gallery_name' => ''), $args));
$args = array(
'post_type' => 'attachment',
'numberposts' => 3,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order',
'post_mime_type' => 'image'
);
$output .= '<script type="text/javascript" src="'. get_bloginfo( 'template_directory' ) .'/js/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="'. get_bloginfo( 'template_directory' ) .'/js/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="'. get_bloginfo( 'template_directory' ) .'/js/lightbox.js"></script>
<script type="text/javascript" src="'. get_bloginfo( 'template_directory' ) .'/js/bjqs-1.3.min.js"></script>
<link rel="stylesheet" href="'. get_bloginfo( 'template_directory' ) .'/css/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
';
$output .= '
<script type="text/javascript">
jQuery(window).load(function() {
jQuery(".gallery-slider").bjqs({
width : 639,
height : 300,
animtype : "slide",
animduration : 450,
animspeed : 4000,
automatic : false,
showcontrols : true,
centercontrols : false,
nexttext : "Next",
prevtext : "Prev",
showmarkers : false,
centermarkers : false,
keyboardnav : true,
hoverpause : true,
usecaptions : true,
randomstart : true,
responsive : true
});
});
</script>';
$output .= "<div class='gallery-slider' style='margin-bottom:10px;'><ul class='bjqs'>";
$attachments = get_posts( $args );
if ( $attachments )
{
foreach ( $attachments as $attachment )
{
$output .= "<li>";
$output .= "<a rel='example_group' href='".wp_get_attachment_url( $attachment->ID )."' title='". get_the_title()."'>";
$output .= "<img width='639px' height='300px' src='".wp_get_attachment_url( $attachment->ID )."' />";
$output .= "</a>";
$output .= "</li>";
}
$output .= " </ul></div>";
}
return $output;
}
add_shortcode( 'gallery' , 'gallery_filter' );
foreach? I don't recognizegallery_first_image. Where did that come from from? Based on the way you are using it I'd expect it to return a string... just a guess though. – s_ha_dum Dec 6 '12 at 5:07foreachseveral times. Which time triggers the error? Do you know? If so, please narrow the problem down. – s_ha_dum Dec 6 '12 at 5:14