2

Are featured thumbs uploaded the same as other images and have their own attachment post url?

I'm trying to utilize the 3.0+ post formats and am using the featured image when creating a post under the 'image' post format. I would like to link the image from the blog loop to its attachment page, which I have already customized for my gallery post format images.

Looking for the right direction. One thing I noticed is that custom post types can have their own page templates e.g.:

single-post_type.php

but post formats do not?

So my questions: 1. - how do you link a featured image from the blog home page to its attachement page (or what is the best solution if it does not have one)? 2. - is there a way to create custom 'single' pages for post formats (or do I use conditionals on single.php)?

Thanks.

1 Answer 1

4

Question 1: How do you link Featured Image to its Attachment Page

In the loop:

<?php if( has_post_thumbnail() ) : ?>
<a href="<?php echo get_attachment_link( get_post_thumbnail_id() ); ?>">
    <?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>

Question 2: Post Format Templating

Post formats are actually just a custom taxonomy with a fancy UI. Hence, you should be able to access and style the post format archive pages via the template hierarchy (admittedly, I've never tried), but you can't style the individual pages.

Lucky for us though, Twenty Eleven shows us the way. Line 27 of index.php:

<?php get_template_part( 'content', get_post_format() ); ?>

get_template_part() is a great function, and you should just read it's Codex entry. It's better than me trying to rewrite it as an answer.

Now, in that loop, you create a file called content.php for a fallback and then add content-video.php, content-link.php, etc. for whichever formats you want to customize.

4
  • mrwweb,thanks for the detailed answer. The first worked well, thanks. I have used the get_template_part() function to customize loop output for each format. Is there, however, a way to customize the single pages as well, much like you can do with custom post formats by naming files: 'single-books.php' for example. As another example, I would like to use a full width single page for the image post format, which is where I was going with this question. Or is linking to the attachment page the best way to accomplish this? Appreciated!
    – jw60660
    May 17, 2012 at 3:12
  • I would just use the same pattern but with a different template name. Twenty Eleven has single.php with get_template_part( 'content', 'single' ); but there's no reason you couldn't use 'post', get_post_format(). Taken to the extreme, that could be the only line in single.php. Elsewhere, you can always test if( get_post_format() == 'image' ) { // do stuff }. You're probably right that in an ideal world, it would integrate better into the template hierarchy, but these are the tools we have to work with.
    – mrwweb
    May 17, 2012 at 5:56
  • With respect to a video post format I think I could just style video.php because I believe that MIME type is the first thing WordPress will look for. I know this works for image.php.
    – jw60660
    May 17, 2012 at 16:13
  • Read this. That is for attachments, not post formats.
    – mrwweb
    May 17, 2012 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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