Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to style the attachment page for each gallery differently, but i'm not sure how (sorry for the noob question, i'm still new to wp development!). I was hoping i could use Attachment.php for one and Image.php for the other, but Image.php overrides both because both are simply Galleries of images. I suppose i might have to add some sort of Else IF type statement to attachment.php, which would sub-divide the galleries...but in that case i'm not sure how i can have the .php distinguish between each one.

any and all help here would be much appreciated!

thanks, eric

share|improve this question
    
Can you explain/clarify what you're trying to do with the different attachment.php template files? –  Chip Bennett Aug 22 '11 at 20:16
add comment

1 Answer 1

Every attachment in a gallery has its post_parent set to the ID of the gallery post that it is attached to. So if you have two gallery posts, each with several images, then you can tell which gallery post the attachment is in (in image.php) by examining that post_parent.

So for example, say you had these (numbers are the ID's of the posts):

  • Gallery Post 1
    • Image post 2
    • Image post 3
    • Image post 4
  • Gallery Post 5
    • Image post 6
    • Image post 7
    • Image post 8

Now, in image.php, you get the $post in the Loop. So if I was looking at Image Post 7, then $post->post_parent would be set to 5. If I was looking at Image post 4, then $post->post_parent would be set to 1.

With that ID, I could do a get_post or something to get the post parent, or I could make a switch-case to do something different depending on the ID, or whatever. How you do it kinda depends on how exactly you're distinguishing amongst these two different galleries and what it is that you're displaying or styling differently.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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