• Is it possible to display the posts per category so that when you click into a certain category, the most recent posts are displayed.

    I’ve looked at this code from the Codex:

    <ul>
    <?php
    $posts = get_posts('numberposts=5&offset=1&category=1');
    foreach($posts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> ?></li>
    <?php endforeach; ?>
    </ul>

    Which will display the latest 5 posts for the category with id=1.

    Is it possible to auto-detect the category id and display the latest posts under that category?

    Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think this is what you want:

    <?php $yourcatid = intval( get_query_var('cat') ); ?>

    Thread Starter checksum

    (@checksum)

    Thanks Michael – how would you put that together to output the Category posts per categort?

    If you are asking in regards to your example above then:
    <?php $yourcatid = intval( get_query_var('cat') ); ?>
    <ul>
    <?php
    $posts = get_posts('numberposts=5&offset=1&category=' . $yourcatid);

    .
    .
    .

    Thread Starter checksum

    (@checksum)

    thats not working out.

    <?php $yourcatid = intval( get_query_var('cat') ); ?>
    <ul>
    <?php
    $posts = get_posts('numberposts=5&offset=1&category=' . $yourcatid);
    foreach($posts as $post) :
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> ?></li>
    <?php endforeach; ?>
    </ul>

    It messes with the page – some posts don’t show and the resulting links don’t work :<

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘display posts per category’ is closed to new replies.