How do you put the most recent post in home Page (6 posts)

  1. Ibis3
    Posted 8 years ago #

    I'm using a Page as the home page of the site (WordPress is in my root) and I'm currently using the default page.php as the template for that page. So it's obviously using the Loop to call in the Page content; following that content, I'd like to append the most recent post. Does this mean I'd have to use multiple Loops? (I tried reading that page in the codex, but got lost very quickly.)

    Any help would be appreciated. The site is at http://www.advancedpps.ca if you'd like to take a look.

  2. Kafkaesqui

    Posted 8 years ago #

    "Does this mean I'd have to use multiple Loops?"

    In a word: yes.

    Going beyond the one word, first suggestion is to set up a custom Page template you assign to your 'home' Page. Easiest way to do this is to make a copy of your current page.php, name the copy something like home-page.php, and make the changes in it mentioned at the link above so you can assign it.

    Next step is to add the second loop. You'll need to set up a custom query for this since just duplicating The Loop is not enough. You can customize a post loop through the use of query_posts():


    For this, something as simple as:

    <?php query_posts('showposts=1'); ?>

    should do.

  3. Ibis3
    Posted 8 years ago #

    Forgive me for being a bit dense, but:

    So do I put the whole Loop in again with this tag before it, or just this tag following the Loop that's already there?

  4. moshu
    Posted 8 years ago #

    This might help.

  5. Kafkaesqui

    Posted 8 years ago #

    "So do I put the whole Loop in again with this tag before it?"

    In a word: yes.

    (No need for more than one this time.)

  6. Ibis3
    Posted 8 years ago #

    The boss changed her mind, so now the goal is to leave the home page as is and show the two most recent posts displaying in full on the blog page. I created a separate page template (bloghome.php) and a new page called 'blog' with no content and assigned that as the "posts page" in the admin dashboard. Two problems:

    1. It's not showing only 2 posts though I've put in a query_posts tag
    2. I'm not sure if there's a way to show complete posts since the (current) posts contain 'more' tags. (This was done for the sake of the category pages.)

    This is the relevant part of the code of the bloghome.php template:

    Template Name: Bloghome
    <?php get_header();
    <div class="narrowcolumn">
    	<?php include(TEMPLATEPATH . '/top-menu.php'); ?>
    <?php query_posts('showposts=2'); ?>
    	<?php if (have_posts()) : ?>
    		while (have_posts()) : the_post(); ?>
    	<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    		<div class="entry">
    			<?php the_content(); ?>
    			<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
    			<?php the_category(', ') ?> <?php edit_post_link('Edit', '<p>', '</p>'); ?>
    			<?php trackback_rdf(); ?>
    			<div class="comments-template">
    				<?php comments_template(); ?>
    	<?php endwhile; ?>

    What am I doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic