Forums

Display different amount of posts than set in your "Reading Settings" section? (5 posts)

  1. beans_etc
    Member
    Posted 2 years ago #

    I have a blog that I've set to show 6 posts per page in my Settings panel. This is good when just browsing through the most recent entries, except when someone decides to select a monthly archive which happens to have more than 6 posts in it, I don't want it split into multiple pages.

    Is there a way to have monthly archives display ALL posts in that month (including 6+) but at the same time not change the posts per page in regular blog browsing?

    I'm assuming it's going to have something to do with conditional comments or WP queries... but I'm not that familiar with PHP so I don't know how to properly write whatever bit of code I'd need.

    Right now the archive is called via a <select> menu with the following code:

    <select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
       <option value=""><?php echo attribute_escape(__('Recent Posts')); ?></option>
       <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?>
    </select>

    The requested monthly archive is then displayed using the wordpress loop:

    <?php if (have_posts()) : ?>
       <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    Archive: <?php the_time('F, Y'); ?>
    <?php } ?>
    <?php while (have_posts()) : the_post(); ?>
       (POST TEMPLATE HERE)
    <?php endwhile; ?>

    URL of blog in question: http://www.beans-etc.com/fangirl/

    I would really appreciate any help in how to write this bit of code or a link to maybe a site/tutorial that already has this...?

  2. JarretC
    Member
    Posted 2 years ago #

    <?php if (have_posts()) : ?>
       <?php
       $query = new WP_Query( 'posts_per_page=-1' );
       $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    Archive: <?php the_time('F, Y'); ?>
    <?php } ?>
    <?php while (have_posts()) : the_post(); ?>
       (POST TEMPLATE HERE)
    <?php endwhile; ?>

    Try that

  3. beans_etc
    Member
    Posted 2 years ago #

    I added the one new line (as far as I can tell it's just the one line you added, correct?) and it didn't appear to change anything.

    This is an example of an monthly archive page with more than 6 posts -- as you can see it still has the pagination link at the bottom to view more: http://www.beans-etc.com/fangirl/2008/12/

  4. JarretC
    Member
    Posted 2 years ago #

    Yes it was just the one new line...try moving it to..

    <?php if (have_posts()) : ?>
       <?php
       $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    Archive: <?php the_time('F, Y'); ?>
    <?php } ?>
    <?php
       $query = new WP_Query( 'posts_per_page=-1' );
       while (have_posts()) : the_post(); ?>
       (POST TEMPLATE HERE)
    <?php endwhile; ?>
  5. beans_etc
    Member
    Posted 2 years ago #

    Nope, still doesn't appear to work. :c (Thank you very much for all the help you're offering though, I really appreciate it.)

Topic Closed

This topic has been closed to new replies.

About this Topic