Post formats template

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?

Related posts

2 comments

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

    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?

    Please take a look at WordPress Codex – Template Hierarchy section.

    I would like to know what template wordpress uses to display post
    formats archive pages?

    An archive ( posts by year, month, day ) page, normally runs over archive.php template. A category archive page runs over category.php template.

    Also is there a way to know if loaded page is post formats archive
    page?

    Yes there is. You can use is_archive(); Conditional Tag.

    UPDATE

    is there a way to show all posts from one post format? For example
    using archive.php template show all posts with ‘image’ or ‘quote’ post
    type?

    Yes there is. You can display specific format posts in your archive.php with pre_get_posts action hook. If you take a look at WP_Query arguments you will find tax_query. It is an array of taxonomy parameters.

    Example usage:

    //in functions.php
    add_action( 'pre_get_posts', 'wpse_show_posts_by_format' );
    function wpse_show_posts_by_format($query){
      //We are not in admin panel and this is the main query
      if( !$query->is_admin && $query->is_main_query() ){
        //We are in an archive page
        if( $query->is_archive() ){
          $taxquery = array(
            array(
              'taxonomy' => 'post_format',
              'field'    => 'slug',
              'terms'    => array( 'post-format-quote', 'post-format-image' )
            )
          );
        //Now adding | updating only to main query 'tax_query' var
        $query->set( 'tax_query', $taxquery );
        }
      }
    }
    

    Hope it helps!

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

    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?

    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), than taxonomy.php, archive.php and index.php.

    Also is there a way to know if loaded page is post formats archive
    page?

    Again it is a taxonomy. So is_tax() or is_tax('post_format') and is_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.

Comments are closed.