Displaying all Video Post Formats to Page

I am creating a video-archive page for all the posts_format with video.

Currently, I have:

<?php $format = has_post_format('video', $post_id); ?>      

<?php

if($layout != "fullwidth") {
    echo '<div class="page_inner">';
}

if (have_posts()) : while (have_posts()) : the_post();

    vntd_blog_post_content();

endwhile;

This is not working, but I do not think I’m far off.

What am I doing wrong?

1 Answer
1

I’m not quite sure if you need a dedicated page or a true archive page for this, but here is the two options

If you need a dedicated page to display video post formats, you can make use of a custom query with a tax_query as post_format is just another build in taxonomy with post-format-video being a term to the post_format taxonomy. Your query on your page template should look something like this

$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => 'post-format-video'
        )
    )
);
$q = new WP_Query( $args );

if ( $q->have_posts() ) {
    while ( $q->have_posts() ) {
        $q->the_post() );

        // Your loop

    }
    wp_reset_postdata();
}

If you need to create a specific archive page for video post format only, you can create a special taxonomy template for this by simply copying your index.php template and renaming it to taxonomy-post_format-post-format-video.php. Everytime you visit this taxonomy page at example.com/type/video or you click on a post-format-video link, this template will be exclusively used to display video post format posts.

Reference: Template Hierarchy

EDIT

Your comment

news.diginomics.com/type/video What do I name my php file to take advantage of this URL hierarchy?

As I stated, you need a taxonomy template as post_format is one of the 4 build in taxonomies. For a video post format specific template, copy your index.php and rename it

taxonomy-post_format-post-format-video.php

This template will be used everytime you visit news.diginomics.com/type/video

For interest sake, please see this answer I have done about taxonomies

Leave a Comment