I'm creating a Wordpress Theme, and I want to create few Page Templates for creating Blog pages with different layouts. So for example, I want to have blog-4-column.php, blog-3column.php and blog-list.php, for giving the user 3 different layout options for having a Blog Page. Now I'm able to list blog posts in my index.php file using this code:
if (have_posts()) : while(have_posts()) : the_post(); ?>
<?php get_template_part('content', get_post_format()); ?>
<?php endwhile; else : ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('no-posts'); ?>>
<h3>No Posts found</h3>
</div>
<?php endif;
Where I have content.php, content-link.php, content-gallery.php to display posts of different Post Formats. Now the only way I know how to do this in a page template is by using WP_Query, as the post type in the page template would be 'pages' and using the above code will list the registered Pages and not Posts.
I just want to know if there is anyway I can use the same 'content-post-format' files for this, as I don't want to create 3 or 4 'content-post-format' files for each individual Blog Page Template that I would create.
I've searched around for this and one I found most useful was on Tutsplus, but still it doesn't cover having different 'content-post-format' files and also having few different Page Templates for listing Blog posts in different ways.
Please let me know about this and thank you.
get_post_format
depends on the current$post
object in the loop, which will work the same whether it's the main query or a custom query.