WordPress.org

Ready to get started?Download WordPress

Forums

Showing single category on custom home page (5 posts)

  1. jzader
    Member
    Posted 6 years ago #

    I am running WP 2.3.1 with a custom home page, where I need to display a list of the four most recent posts within a certain category ("announcements").

    Here is the code I'm using so far, but it doesn't select for category:

    $news = $wpdb->get_results("
    	SELECT
    		ID,
    		post_title,
    		post_date,
    		post_content
    	FROM $wpdb->posts
    	WHERE
    		post_status='publish'
    	ORDER BY ID DESC LIMIT 4");
    foreach($news as $np){
    	[display results here]
    }

    How could I modify this query to display only results from a single category? My server is running MySQL 5.0, if that matters.

  2. greatbig47
    Member
    Posted 6 years ago #

    This is simular to what I'm looking for...

  3. moshu
    Member
    Posted 6 years ago #

  4. Jeremy Clark
    Moderator
    Posted 6 years ago #

    Why not use query_posts instead of directly querying the database.

    <?php query_posts("cat=3"); ?>
    Your loop stuff goes here
  5. jzader
    Member
    Posted 6 years ago #

    jeremyclark13,

    I had never come across query_posts before, but it's just what I had been searching for and it works BEAUTIFULLY.

    Thank you!

    Looks like Moshu was pointing out the same thing. Thanks, guys.

Topic Closed

This topic has been closed to new replies.

About this Topic