I would like to know what template wordpress uses to display post formats archive pages? What is parent template file that is used when there is no specified template file and what is specified template file that covers all post formats templates? Also is there a way to know if loaded page is post formats archive page?
2 comments
Comments are closed.
Post formats are used to customize posts according to their “meta” content, but they are always posts and as posts they will be listed on archive and category pages.
Please take a look at WordPress Codex – Template Hierarchy section.
An archive ( posts by year, month, day ) page, normally runs over
archive.php
template. A category archive page runs overcategory.php
template.Yes there is. You can use
is_archive();
Conditional Tag.UPDATE
Yes there is. You can display specific format posts in your archive.php with
pre_get_posts
action hook. If you take a look atWP_Query
arguments you will findtax_query
. It is an array of taxonomy parameters.Example usage:
Hope it helps!
Post format is a taxonomy.
Not post type, nor meta.
The difference from categories, tags, custom taxonomies and post format is that the post format terms can be (at this time) a set of 9 terms.
Note that the post format ‘Standard’ does not exist, setting a post to standard post format means set no post format.
So arbitrary post format cannot exist, but the ones that exist are taxonomy terms.
Note also that the slug of this taxonomy is something like
post-format-{$format}
, e.g.post-format-quote
.Once they are taxonomy terms, you have to see Template Hierarchy regarding taxonomy:
So
taxonomy-post_format-{$slug}.php
(e.g.taxonomy-post_format-post-format-quote.php
) is the first template thet wp look for.After that
taxonomy-post_format.php
(this is included in twentythirteen theme), thantaxonomy.php
,archive.php
andindex.php
.Again it is a taxonomy. So
is_tax()
oris_tax('post_format')
andis_tax('post_format', 'post-format-quote')
will all work.I bet that now you are asking what is the url that request post format archives?
I’ve to say that when no pretty permalinks are activated the link is something like
http://example.com/?post_format=quote
(http://example.com/?post_format=post-format-quote
will also work).With pretty permalinks activated, by default, it is something like:
http://example.com/type/quote
. (http://example.com/type/post-format-quote/
will also work)Note that the url
http://example.com/type/
(with no given type) will result in a 404 error.I’ve said ‘by default’ because the rewrite base ‘type‘ for post format can be changed via the
post_format_rewrite_base
filter.However, to get the correct link to the post format archive is possible to use the get_post_format_link function.