Post formats template

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!

Leave a Comment