WordPress.org

Ready to get started?Download WordPress

Forums

Display content of latest post of certain category (3 posts)

  1. Sphagnum
    Member
    Posted 4 years ago #

    I'm building a custom website for a group of friends who are getting a band off the ground. I'm building the website mostly in some basic html, styled with CSS, but in cooperating some WordPress functions into it so that these guys (who are not very tech savy) can make use of the WordPress editors on the back end to keep their website up to date (and limiting the time I have to spend doing anything with it). So here's what I'm trying to do, but so far haven't been able to figure out by myself.

    On the front page of this website, I have a the theme all set up and a small area dedicated to a "welcome message" where I want the guys to be able to update this with maybe where they are playing most recently and whatnot. My idea is to have any posts they make in WordPress that use the Category slug "FrontPage" or something like that be listed here. But I only want the LASTEST post of that category to be listed here. I have a basic loop written in now:

    <?php while (have_posts()) : the_post(); ?>
    	<?php the_content(); ?>
          <?php endwhile; ?>

    But that is going to show ALL posts in ALL categories, how to edit it so only the LAST post in ONE category shows up.

    Any help in the right direction would be greatly appreciated!

  2. stvwlf
    Member
    Posted 4 years ago #

  3. Sphagnum
    Member
    Posted 4 years ago #

    Awesome, that's what I needed. Thanks. New code is

    <div id="FrontPageTextBox">
    <?php query_posts('cat=3&posts_per_page=1'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    	<?php the_content(); ?>
          <?php endwhile; ?>
    
    <?wp_reset_query(); ?>
    </div>

    And it works perfectly.

Topic Closed

This topic has been closed to new replies.

About this Topic