WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] The Loop: posting only the most recent post to a static homepage (5 posts)

  1. particlepat
    Member
    Posted 5 years ago #

    I'm having some issues writing the loop for my wordpress site. There will be a static homepage that will contain the header, footer, top navigation bar, a containing holding some navigation buttons that will only be visible on the home page, and then a smaller container to the right of that one that will hold a small snippet/excerpt of my most recent blog post.

    I am starting to get really frustrated when I try to write the loop for the single blog post. I want to show the blog title that links to the post, the authors name, the excerpt, a link that says "Read the rest of this entry", the number of comments, and a link to leave a comment. I do not want a list of comments to appear on the homepage though.

    I have been able to get the title, the authors name and an excerpt of the blog, but it shows an excerpt for all of my entries, and like I said, I only want one. Can someone please give me some pointers or help me write the code for my loop?

    *I will have a separate page designated to showing all blog posts, so I'm assuming that will be a completely different loop. I'm only focused on the first loop as of now.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    What's the code for your loop right now? Should be a simple matter of adding a query_posts call to adjust the parameters of the main query.

  3. particlepat
    Member
    Posted 5 years ago #

    <?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post">
    				<h1 class="toptitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
    				<p class="topMeta">by <?php the_author_firstname(); ?> <?php the_author_lastname(); ?></p>
    
    			<div class="entry">
    				<?php the_excerpt(); ?>
    			</div>
    
    			</div> <!-- Closes post --><br />
    
    	<?php endwhile; ?>
    
    	<?php endif; ?>
  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Okay. Add query_posts('showposts=1'); right before that Loop.

  5. particlepat
    Member
    Posted 5 years ago #

    Thank you very much, I knew it was something incredibly easy like that. You're the man.

Topic Closed

This topic has been closed to new replies.

About this Topic