• I’m wondering what all the shortcodes really are for the new 2.5 WP gallery. I want my images to be displayed in order based on timestamp or filename if possible. I’d also like to know the rest of the shortcodes if I so desire to use them. I see nothing in the documentation that lists them all out, other than to say they’re usable and a few examples.

    I’d also like to know where the code is located to change or eliminate the image linking to a comment page. Maybe my eyes are going bad but I couldn’t find it.

    Thanks in advance!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The gallery shortcode is defined in wp-includes/media.php, line 333 and onwards. In its simplest form, a [gallery] should suffice. The sort order appears to be fixed, but the code is easy enough to change.

    However, there appears to be a bug in the code, probably a last minute cleanup that didn’t work as expected.

    The call to retrieve the images (child pages) is wrong, giving malformed SQL-statements later on. If you know your way around the patch tool, you can apply my diff found here.

    No guarantees, but it WorksForMe<tm>, well enough until they issue a proper fix.

    A few links to how it’s supposed to work, parameters etc can be found if you search for gallery shortcode.

    If I had followed my own link, I would have seen that there indeed is an order by-parameter in the short code. If you want to remove the link around he image, you probably have to hack the source, however.

    Thread Starter cdifoto

    (@cdifoto)

    That doesn’t really help me much since I’ve seen those pages. I simply want to know what those little codes are for the orderby. I can’t use them if I don’t know what they are. In other words, I want to change the default but I don’t know what to change it to. Unless, as you said, there’s a bug in the code.

    Not that it matters much now. I downloaded Zoundry Raven and will be using that.

    Same problem here. It seems that this new feature is very badly documented and with several limitations. I’d like to:

    1. Order by name;
    2. Paginate the gallery (every 12 thumbs, for example);
    3. Skip the medium sized image.

    These are rather simple operations, i think, and they would fill most needs – no plugin would be required…

    Fixing the call to get_children() in gallery_shortcode() as rtz suggests should allow [gallery orderby="post_name ASC"] to sort the thumbnails by name, but the prev and next links will still be sorted in the default. That’s handled in adjacent_image_link() in media.php and I’m not familiar enough with the code yet to know if you can access the orderby shortcode option down there or if you have to just hard code your desired sort order until an official fix is released.

    Let me see if I understand what you’re trying to do. . . are you trying to remove the link to the attachment page when you post (an) image(s) with the gallery feature?

    If so, I had the same irritation, and so I went to the post-template.php (it’s in the wp-includes folder), edited this piece of code :

    // get an attachment page link using an image or icon if possible
    function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false) {
    	$_post = & get_post( intval($id) );
    
    	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
    		return __('Missing Attachment');
    
    	if ( $permalink )
    		$url = get_attachment_link($_post->ID);
    
    	$post_title = attribute_escape($_post->post_title);
    
    	$link_text = wp_get_attachment_image($id, $size, $icon);
    	if ( !$link_text )
    		$link_text = $_post->post_title;
    
    	return "<a href='$url' title='$post_title'>$link_text</a>";
    
    }

    All you have to do is remove the url tags surrounding “$link_text” (in the “return” line of code”). However, if you ever want to link to an attachment page in the future, I would advise you not to do this, because it removes the link to attachment pages from ALL attachments.

    (Disclaimer : I am not a php pro, so I can’t guarantee it won’t create some other type of issue, but it worked wonderfully for me.)

    I found that the orderby parameter of gallery in 2.5 was broken. An incorrect SQL statement was being produced that meant that any orderby was ignored. This is now fixed in 2.5.1 and introduces a new value: ‘orderby=RAND()’ for random ordering.
    See this trac entry for more.

    I think I found out how skip the link to the attachment page and instead, link directly from the gallery thumbnail to the full size image:

    Find out function wp_get_attachment_link in your post-template.php file (located in wp-includes) and change it to look like this (one extra code line, one extra comment line):

    // get an attachment page link using an image or icon if possible
    function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false) {
    	$id = intval($id);
    	$_post = & get_post( $id );
    
    	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
    		return __('Missing Attachment');
    
    	if ( $permalink )
    		$url = get_attachment_link($_post->ID);
    
    	$post_title = attribute_escape($_post->post_title);
    
    	$link_text = wp_get_attachment_image($id, $size, $icon);
    
    	//modification introduced to force the gallery shortcode thumbnail hyperlink to the full size image directly, rather than the attachment page
    	$url = wp_get_attachment_url($_post->ID);
    
    	if ( !$link_text )
    		$link_text = $_post->post_title;
    
    	return "<a href='$url' title='$post_title'>$link_text</a>";
    }

    Let me know if this works for you!

    The gallery shortcode is defined in wp-includes/media.php, line 333 and onwards. In its simplest form, a [gallery] should suffice. The sort order appears to be fixed, but the code is easy enough to change.

    Can somebody point me to where the shortcode definition has been moved to? Media.php seems missing in v2.6. There’s still this line in the HTML source: <!– see gallery_shortcode() in wp-includes/media.php –>, but I can’t even find the gallery_shortcode() function when searching the WP sourcecode.

    Bah! Never mind, been bitten by a local/server mismatch. Of course media.php exists, just not on my local harddrive…

    thesmu

    (@thesmu)

    thank you so much phiv! worked like a dream!!

    Ovidiu

    (@ovidiu)

    any news on the pagination, i.e. after 30 thumbs make a new page for the gallery? i.e. I don’t want to show more than 30 thumbs per page of the gallery…

    besides, my installation seems not to obey the sort = desc or asc ?? anyone else with this problem?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘2.5 Gallery ShortCode’ is closed to new replies.