WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Customizing single.php only if used by the gallery shortcode (8 posts)

  1. MartienWPR
    Member
    Posted 1 year ago #

    I am rather satisfied about the gallery shortcodes like [gallery ids="237,238"] etc. What I noticed is (thanks to the wonderful what the file plugin) the images when clicking on them are shown in the single.php template. I would like to make some minor changes in this template but only if the template is called by the gallery. The changes should not affect single.php when it is used for ordinary posts etc. I have been looking if there was something available like single-sometag.php within the template hierarchy but couldn't find anything that would match my needs. It also could be helped if I could "tell" the gallery shortcode to use one of my custom templates rather than single.php . Thanks for any help

  2. David Williamson
    Member
    Posted 1 year ago #

    I'm not sure if I completely understand what you're asking for, so correct me if I've misunderstood.

    It sounds like you want to customize the page that's displayed when you click an individual image in a gallery and look at a single picture at a time. If that's the case you can create an attachment.php file (or image.php file) to handle that specific case. The codex page on Template Hierarchy has some info on creating attachment pages and some of the options you can use.

  3. MartienWPR
    Member
    Posted 1 year ago #

    David thanks, as far as I see your reply I think you did understand my question, I think that image.php or attachment.php could resolve my problem, I still won't mark my question as solved but there is a good chance I will be able to do so, otherwise I will ask additional question thx again

  4. MartienWPR
    Member
    Posted 1 year ago #

    I added image.php and actually the theme now uses it for gallery images.
    What I would like to achieve is that the next image and previous image links only will guide the visitor through the current gallery, and not to images in other gallery (which now occurs when the last image of the gallery is shown). An additional link to the page (it are pages, not posts)where the gallery had been created would also be very welcome.

  5. MartienWPR
    Member
    Posted 1 year ago #

    I am still puzzled about some issues related to this , I am trying to refer on image.php to the page where the images was attached as a gallery item, 'get_post($post_id)->post_parent; ' and similar statements don't refer to that page, they refer to the image page itself, when I could find a solution for that, a big part of the problem would be solved.

  6. David Williamson
    Member
    Posted 1 year ago #

    I'm not really sure about how to fix the next/previous links on an attachment template. You might want to post that as a new question here on the forums.

    The only thing I can think of for your link to the parent post would be make sure that the images in your gallery are actually attached to the page (you can check in the Media Library, there is a column - Uploaded To - that indicated what post media images have been attached). Then I would think the post parent would be set correctly and you could create a link.

  7. MartienWPR
    Member
    Posted 1 year ago #

    Hi David,
    Thanks very very much... entering the correct "uploaded-to" option already solved much more of my problem. I will check everything tomorrow again (time to sleep here in Holland) and mark the problem as solved unless I would have additional questions.

  8. MartienWPR
    Member
    Posted 1 year ago #

    Sorry forgot to mark it as solved :)

Topic Closed

This topic has been closed to new replies.

About this Topic