WordPress Post Format Archives
A quick one for you. Yesterday I needed to know exactly how WordPress handles archive pages for their new Post Formats – such as ‘link’, ‘aside’ and ‘gallery’. After quite a bit of faffing around, i found the magic formula is as follows:
taxonomy-post_format-post-format-{name}.php where {name} is the name of the post format. So, for example, if you want an archive for your link post format, you’ll want:
taxonomy-post_format-post-format-link.php
There you go, job’s a good’un.
As an aside, if you are using query_posts() on these template pages, you might want to know how to just get posts of a certain post format. The code you need it similar to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php $links_query = query_posts( array( 'posts_per_page' => 10, 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-link', ), 'operator' => 'IN' ) ), 'offset' => $offset, 'paged=' . $paged ) ); ?> |
on June 5, 2011
at 3:52 am
Good stuff. I stumbled on your post while looking for the same thing. After some research I also realized that WordPress has a function to get the archive link to the “post-format” taxonomy using get_post_format_link();
You can also stick this “if” condition in your archive.php
if ( is_tax( ‘post_format’ ) ) :
// your code here
endif;
get_post_format_link() would redirect you to the archive.php page. The output would be something like this http://www.example.com/type/aside
on June 5, 2011
at 12:09 pm
Aziz, great find! Some folks will certainly find that useful.
I have a redirect set up for all my links on http://iamfriendly.com/links/ which sends folk to http://iamfriendly.com/blog/type/link/ (blog being my prefix).
Thanks for the comment :)