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
		)
	);
 
?>

2 thoughts on “WordPress Post Format Archives

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Notify me of followup comments via e-mail. You can also subscribe without commenting.