Horizontal Posts

I can’t seem to find much on this, it may be the way I am wording the question.
i would like to create a section of content on the home page with columns in it. - let’s say 3.

I would like to display the latest three posts of news in these three columns.
what is the best way to go about this?

Im still a novice with coding, and I don’t have a full grasp of php, although I am studying it, so Im struggling as I don’t quite know where to start on this one.

I achieved it on a theme I built from the ground up with the help of a tutorial but don’t know which bits of php are relevant, I really want to be understanding what I am doing at this point.

if there are any links anyone could point me to on this topic I would be grateful!

The WP Codex is your friend

The following example (untested) meshes WP Query with the loop found in index.php of the Roots theme

	$query_recents = new WP_Query ( array( 'posts_per_page' => 3 ) );
	if ( $query_recents->have_posts() ):
<section class="recent-posts row">
	<?php while ( $query_recents->have_posts() ) : $query_recents->the_post(); ?>
		<div class="col-sm-4">
			<?php get_template_part('templates/content', get_post_format()); ?>
	<?php endwhile; ?>
        <?php wp_reset_postdata(); ?>
<?php endif; ?>

There is nothing Roots specific to this. You can create a template for this (e.g. templates/recents.php) and include it in your front-page.php using

<?php get_template_part('templates/recents'); ?>

or even create a shortcode in a functionality plugin and include the shortcode in your edit screen. Note, the code for the shortcode would greatly differ. link

1 Like

@enollo thats similar to what is in my other site. thank you for explaining, that makes sense to me mostly. except if I were to put this in my home page template, what is this bit of code doing?

<?php get_template_part('templates/recents'); ?>  

is it bringing another page template into my page template?

Best wishes,


@enollo was proposing you create a template part with the recents code and then reference that template part instead of adding the code directly to your home template.

1 Like

Yes, @Foxaii is right. You don’t have to place it in a template part, but if you did it would make using it in multiple places later much easier.

ahh. thats useful to know, thank you!