0

I'm looking for solution for a gallery on a WP page that shows multiple thumbnails of images in that gallery, but not all thumbnails in gallery (like default Galleries in WP works). I want (i.e.)certain 3 thumbnail images to show up on page, which (each one of them) leads to the same gallery with more than 3 images (i.e. 7 images). Additionally (it would be uber-fantastic), if it would throw in description how many images there are in the gallery (some WP function, you know?).

It should work like from the shortcode with images with such (fabricated) property : "show-thumbnails"

[gallery ids="152,153,103,104,102,64,60" show-thumbnails="152,153,103"]

Is it possible in WordPress? Perhaps you know some plugin that has such options ? Or know how to pass some additional params to WP ? Thanks!

  • Be aware that a request for a plugin recommendation is going to be off-topic, and as written you are asking for someone to write a fair bit of code for you. You'd be better off making an attempt at writing this yourself and asking a more specific question when you have trouble. – s_ha_dum Jan 30 '14 at 3:47
  • Sorry, I'm still getting to know this place. Thank you for advice. I am not asking anybody to write code for me - I am looking for a solution. – Jan Desta Jan 30 '14 at 16:08
  • Yes, but the solution you are asking for requires substantial code. Sometimes such questions get answers (looks like you got lucky) but often they don't. You are better off starting the code yourself. Just a tip. – s_ha_dum Jan 30 '14 at 16:46
0

It is possible but it needs some developing effort. First of all it is important to know that WordPress default »galleries« are not discrete resources you can address with an separate URL. They are just shortcodes defined on a single posts context.

So what you need to do is to define a URL the thumbnails point to which, of cause, defers from the posts thumbnail. One (not the only) way is, to add a rewrite endpoint to your permalink. Assuming your post permalink is your-domain.tld/2014/a-wordpress-post/ the URL the thumbnails could look like your-domain.tld/2014/a-wordpress-post/thumb/123/. The number on the last part represents the ID of each thumbnail. Endpoints are normally added on init:

add_action( 'init', 'wpse_131753_add_thumb_endpoint' );
function wpse_131753_add_thumb_endpoint() {

    add_rewrite_endpoint( 'thumb', EP_PERMALINK | EP_PAGES );
}

Now, you need to change the way, WordPress renders the gallery shortcode. There's a filter for that called post_gallery. It bypasses the output of the default function called gallery_shortcode() which is defined in wp-includes/media.php.

Let's view some code for this:

add_filter( 'post_gallery', 'wpse_131753_gallery_view', 10, 2 );
function wpse_131753_gallery_view( $output, $shortcode_attributes ) {

    $default_attributes = array(
        'show-thumbnails' => '',
        'order'           => 'ASC',
        'orderby'         => 'menu_order ID',
        'id'              => $post ? $post->ID : 0,
        'itemtag'         => 'dl',
        'icontag'         => 'dt',
        'captiontag'      => 'dd',
        'columns'         => 3,
        'size'            => 'thumbnail',
        'include'         => '',
        'exclude'         => '',
        'link'            => ''
    );
    $atts = shortcode_atts( $default_attributes, $shortcode_attributes, 'gallery' );
    $current_thumb_ID = get_query_var( 'thumb' );
    // build your gallery markup here using
    // $atts[ 'show-thumbnails' ] and 
    // $current_thumb_ID
    // to defer between varous outputs

    if ( $current_thumb_ID ) {
        // here you may want to show the compltete gallery
    } else {
        // and here you may want to show the thumbs in 
        // $atts[ 'show-thumbnails' ]

        // to link to the detailed view use this:
        $permalink = untrailingslashit( get_permalink( get_the_ID() ) ); 
        $thumb_link = $permalink . '/thumb/' . $thumb_ID; 
        // where $thumb_ID is one of the IDs in your atts.
    }
    return $output;
}

The function sould lookup for the default used gallery shortcode attributes and build the html on your belief whether it should show only the three thumbnails when no endpoint is given or a specific thumbnail was clicked (the endpoint contains the ID of the clicked thumbnail). The enpoint's value is stored in the query variable: get_query_var( 'thumb' ).

  • I am grateful for your explanation. Perhaps I'll be able to go alone from here, but I was hoping for some easy solution, that I might have omitted. At least I know there isn't any default WP gallery mechanism that does it, or any - widely known - plugin (because otherwise, I guess, you'd write about it.. or is it prohibited here?). Ps. I've intentionally wrote here and not on StackOverflow because I wasn't looking for developing solution. – Jan Desta Jan 30 '14 at 16:04
0

You can add this code in WP page. For any plugin shortcode to add in WP page:

<?php do_shortcode('[plugin shortcode]'); ?>

like:

<?php echo do_shortcode('[gallery ids="152,153,103,104,102,64,60" show-thumbnails="152,153,103"]'); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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