WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] list recent posts in category (4 posts)

  1. freshyill
    Member
    Posted 8 years ago #

    I'm trying to make a list of recent posts, by date, in one category. I *think* I'm on the right track with this, but i'm not getting the result I expect. Can someone who is more familiar with the workings of the loop help me out?

    This is the result I want:

    Date
    - title of post
    - title of post
    Date
    - title of post
    - title of post

    ... and so on for 7 days total ...

    What I'm getting is more like this:

    September 9
    - title of post
    - title of post
    - title of post

    It's showing the posts for the last seven days, but for all categories, and not breaking them down by date. Can anybody tell me where I'm going wrong?

    This is the code I have:

    <?php $posts = get_posts( "category=2&days=7" ); ?>
    <?php if( $posts ) : ?>
    <div class="recent">
    <h2>Recent album reviews</h2>

    <h3><?php the_time('F j'); ?></h3>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>

    <?php endforeach; ?>

    </ul>
    </div>
    <?php endif; ?>

  2. freshyill
    Member
    Posted 8 years ago #

    OK, I'm getting closer with this. Does anybody have any idea how I might do this? I know there have got to be some people who understand this in here.

    This is the code I'm using:

    <?php $posts = get_posts( "category=3&days=7" ); ?>
    <?php if( $posts ) : ?>
    <div class="recent">
    <h2>Recent album reviews</h2>

    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <h3><?php the_date('F j'); ?></h3>

    <ul>
    <li><a>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>
    </ul>
    <?php endforeach; ?>

    </div>
    <?php endif; ?>

    The output I'm getting is now very close to what I actually want, but I'm getting some stuff that I don't need. The problem is that the list is ending, giving me a blank date spot (which I don't even need), and then starting a new list for the next item.
    Here's the output:
    <div class="recent">
    <h2>Recent album reviews</h2>

    <h3>October 4</h3>

    <ul>
    <li><a href="http://crapfilter.net/blog/?p=14" title="Permanent Link to This is the title of an album review">This is the title of an album review</a></li>
    </ul>
    <h3></h3>

    <ul>
    <li><a href="http://crapfilter.net/blog/?p=13" title="Permanent Link to Of course, you should know by now that this is a test">Of course, you should know by now that this is a test</a></li>
    </ul>
    <h3>September 27</h3>

    <ul>
    <li><a href="http://crapfilter.net/blog/?p=7" title="Permanent Link to This is a new thing for some more tests">This is a new thing for some more tests</a></li>
    </ul>
    </div>

    Any help would be greatly appreciated.

  3. freshyill
    Member
    Posted 8 years ago #

    OK, I decided to say screw this ul stuff and do it as a definition list. It works perfectly. If anybody is interested, here's the code:

    <?php $posts = get_posts( "category=3&days=7" ); ?>
    <?php if( $posts ) : ?>
    <div class="recent">
    <h2>Recent album reviews</h2>
    <dl>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <dt><?php the_date('F j'); ?></dt>
    <dd><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></dd>
    <?php endforeach; ?>
    </dl>
    </div>
    <?php endif; ?>

    What a pain. This is the kind of thing that was absolutely simple to do in Movable Type. I'm thoroughly sold on the power of WordPress, but anybody who says it's easy probably isn't even fooling themselves.

  4. Joshua Sigar
    Member
    Posted 8 years ago #

    edit: nevermind.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags