Support » Plugin: WP Supersized » Fix for WP 3.5 gallery order

  • I have been using WP Supersized for a while, and I like it. I use it to display single portfolio posts with a background gallery slideshow (using the built-in wp gallery).

    However, when upgrading to WP 3.5, and the new gallery, I had some problems ordering the images. The plugin doesn’t seem to adapt very well to the new gallery, which no longer uses images as attachment, instead using a gallery shortcode where images are chosen regardless of being attached or not. The plugin still seems to work, but the ordering of images seems to follow filenames or id’s rather than menu_order (user selected order).

    I made a quick fix for it, which works, but may be improved.

    In WPSupersized.php, inside the function “images_from_wpgallery” (line 888), after populating $images with get_children, add this code:

    global $post;
    $attachment_ids = array();
    $pattern = get_shortcode_regex();
    $ids = array();
    if (preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) ) {   //finds the "gallery" shortcode and puts the image ids in an associative array at $matches[3]
    $count=count($matches[3]);      //in case there is more than one gallery in the post.
    	for ($i = 0; $i < $count; $i++){
    		$atts = shortcode_parse_atts( $matches[3][$i] );
    		if ( isset( $atts[ids] ) ){
    		$attachment_ids = explode( ',', $atts[ids] );
    		$ids = array_merge($ids, $attachment_ids);
    // Only use gallery shortcode if present
    if ($atts) {
    	 $images = $ids;

    Now, a couple of lines below, following “foreach($images as $image) {“, replace the four following lines (declaring four variables), with this code:

    // Only use gallery shortcode if present, else revert to old method (for old posts/pages with attached images)
    if ($atts) {
    $wpgallery_url   = wp_get_attachment_url($image); // full link to the full size image
    $wpgallery_thumburl = wp_get_attachment_thumb_url($image); // full link to the thumbnail
    else {
    $wpgallery_url   = wp_get_attachment_url($image->ID); // full link to the full size image
    $wpgallery_thumburl = wp_get_attachment_thumb_url($image->ID); // full link to the thumbnail
    $wpgallery_title = apply_filters('the_title',$image->post_title); // image title
    $wpgallery_caption = apply_filters('post_excerpt',$image->post_excerpt); // image caption

    Last, you might want to add an option to exclude featured images when using old-style attachment images. You made a fix for this in some post in the forum, but having to edit the plugin myself isn’t good practice…

  • The topic ‘Fix for WP 3.5 gallery order’ is closed to new replies.