WordPress.org

Ready to get started?Download WordPress

Forums

Automatically set numberposts (6 posts)

  1. maerk
    Member
    Posted 8 years ago #

    I'm trying to set up an intelligent archive system for my wordpress entries. So far I've done quite well, see http://beingmrkenny.co.uk/blog/blogarchive.php

    You can enter the month and year as GET variables:

    ?month=jan&year=2004

    What I'd like to do would be to set 'numberposts' to some sort of "max" value, or "all" so that all posts within the date range were given. So far I have had to enter it at 60, which is the maximum number of posts in any month, but when the number of posts is less than that, empty <li> tags are generated.

    Is there a way to set numberposts to something more sensitive?

  2. OnSeduction
    Member
    Posted 8 years ago #

    I don't know if you use the loop for that, but you could use something like:

    <?php query_posts('showposts=10'); ?>
    (http://codex.wordpress.org/The_Loop)

    before the loop, and have '10' as a variable from the GET input.

  3. maerk
    Member
    Posted 8 years ago #

    Hmm, that's interesting, I'll probably use that idea when displaying all posts from a year.

    For the month, though, is there a way of getting the number of posts in that month. I found

    $wp_query->post_count

    but it seems that I'm only requesting the last 15 posts from each month. Is there a way to request ALL posts from a month?

    EDIT: the reason it's 15 is because that's the number of posts per page I've set in options. How to override this...

  4. OnSeduction
    Member
    Posted 8 years ago #

    Maybe something like: if isset get ['month'] query_posts('showposts=10000'), else ...

    so if they ask a month, set the number of posts to appear very large and I think they will then see all posts

  5. OnSeduction
    Member
    Posted 8 years ago #

    Also, be sure to filter the get data for security issues.

  6. maerk
    Member
    Posted 8 years ago #

    Cool, thanks for the heads-up on the security issue.

    I don't know if I can do anything with GET data, though. Does anyone know how to override the setting in options for posts-per-page?

    Or how to count posts within a month?

Topic Closed

This topic has been closed to new replies.

About this Topic