0

I’m building a WP theme using Bootstrap. Aparently, all templates were working fine until I tried to display a list of recent post on the front page. Basically, the loop it’s not displaying posts (it displays a link to the home page instead). When I head to the site’s blog, it enlists the posts correctly. Things you may need to know: The front page is set to display a static page (Home), as well as the posts page (Blog).

I'd like to see the lists of posts on the front page, and if it's possible, show only the last three ones.

Here's the code of front-page.php:

<?php get_header(); ?>

<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<h2 class="text-center">Our Mission</h2>
<img class="img-responsive" src="http://localhost/WP/wp-content/uploads/2014/09/6.jpg"><br>
<p class="text-justify">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<h2 class="text-center">Our Vision</h2>
<img class="img-responsive" src="http://localhost/WP/wp-content/uploads/2014/09/7.jpg"><br>
<p class="text-justify">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
</div>
</div>
</div>

<div class="container">
<h2>Latest Blog Posts</h2><br><br>
<div class="row">
<div class="col-md-8">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><em><?php the_time('F j, Y'); ?></em></p>
<?php the_excerpt(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, there are no posts.'); ?></p>
<?php endif; ?>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
</div>

<?php get_footer(); ?>

Hope you guys can help me. Thanks in advance!

  • To show blog listing, I guess you need to use blog.php instead of front-page.php – Nilambar Sep 25 '14 at 2:41
  • use different files for home and blog – Zammuuz Sep 25 '14 at 5:12
  • Yes, I´m using front-page.php for the home page and home.php for the blog. – user60184 Sep 25 '14 at 16:13
0

If the Home page is set to be a static page like you have, I think that the posts page is supposed to be a different page. http://codex.wordpress.org/Settings_Reading_Screen

You can display your recent posts on front-page.php with WP Query, though: http://codex.wordpress.org/Class_Reference/WP_Query

Here's a mostly inclusive starter code, followed by the loop. It's copied from a sublime text helper I have. You probably won't need most of the parameters for this instance. http://pastebin.com/tjeMW2Rf

  • Yeah, both pages are set to be different static pages. And thank you, the example query you shared solved the problem. One more question. What's the difference between wp_reset_postdata and wp_reset_query? – user60184 Sep 29 '14 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy