WordPress.org

Ready to get started?Download WordPress

Forums

Linking gallery images to parent post and not the image/gallery (3 posts)

  1. jayroh
    Member
    Posted 5 years ago #

    Hey everyone -

    Right now we're using the gallery shortcode to output a 4-column gallery of thumbnails like so:

    [gallery columns="4"]

    But have noticed that the thumbnails are linking to a permalink for each image. We'd ideally like to link to the parent PAGE instead. Is this possible?

    Example -
    GOOD: http://www.site.com/2009/07/permalink-to-post.html
    BAD: http://www.site.com/2009/07/permalink-to-post.html/imagename111

    Is there a setting for the shortcode that would do the first instead of the second? The only option I've seen is for a link attribute being set to "file" ... and haven't found another possible attribute like url, or permalink, or parent. Any ideas?

    Thanks everyone!

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Setting the link attribute to "file" means that the image will link to a bare copy of itself. Setting the link attribute to "post" means that the image will link to a copy of itself within a dynamically created WordPress page.

    There are no other options available without hacking the gallery code. I've got around it by placing the following at the foot of my image.php template files:

    <p><small>Posted under <a href="<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php echo get_the_title($post->post_parent); ?></a></small></p>

    which at least gives a link back to the parent post/page.

  3. palPalani
    Member
    Posted 4 years ago #

    Nice tip! it'z really helps me!

Topic Closed

This topic has been closed to new replies.

About this Topic