show the latest articles of a category (2 posts)

  1. aronchi
    Posted 9 years ago #

    I need to create a simple php file with the posts of the last week putted in a category, to create a simple weekly newsletter.

    I tried to use query_posts(), but it seems to don't work: it has no influence on the loop.

    My code is:

    while (have_posts()) : the_post();
        the_content('Read the full post »');

    of course I tried to search in codex examples, but the examples for me simply doesn't work.
    I only need to get a list of posts, I thought it was a simple thing. Maybe it's easier for me to write an sql query.

    Please help me.

  2. Doodlebee
    Posted 9 years ago #

    Well, first off, your query has to be *outside* of the loop for it to work.

    <?php query_posts("showposts=1"); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post();
        the_content('Read the full post »');

    That code will also only show 1 post (the most recent one made in the entire site). Not the most recent posts of the last week, and certainly not in a specific category.

    For that, you'd need to figure out what today's date is, and then set a conditional to grab all the posts in the last 7 days. Then have it look through those posts and narrow it down to the category you want. *Then* do the Loop.

    I don't know the exact code for it, but that should give you some ideas...

Topic Closed

This topic has been closed to new replies.

About this Topic