• Hey All,

    I’ve come across an interesting issue that I’m trying to resolve.

    On the monthly archive pages for my site (https://www.somesuchstuff.com/blog/), only the last 5 posts are visible. However, there are 14 or 15 posts for the month of May.

    I’ve figured out that if I change the Blog Pages option in Options -> Reading, it will display the archive properly, however, this also changes the output of the main blog page, where I would only like to have the last 5 posts.

    I’m going to take a stab in the dark and guess that this is not supposed to happen. Is there anything in the codex about this issue or tags that I can use to solve this problem?

    Thanks,

    Justin

Viewing 12 replies - 1 through 12 (of 12 total)
  • Nope, that’s how it supposed to work. You told it to display only up to 5 posts at one time and that’s what it’s doing. ??

    The following allows you to set the number of posts for various views:
    https://rephrase.net/miscellany/05/perpage.phps

    Thread Starter functionjunkie

    (@functionjunkie)

    Viper: Hmmm… Yes, I am telling it to do that, and I certainly don’t fault it for doing what it’s told, however, one would assume that the monthly archive will show all the posts for that month, and ignoring the set number of posts to display.

    IanD: That appears to a be a plugin. Should I upload that to my plugins dir?

    Thanks,

    Justin

    Yep, save as perpage.php or something and put it in the plugins directory.

    Thread Starter functionjunkie

    (@functionjunkie)

    Ian,

    Tried that plugin, renders WP 1.5.1 useless. After activating, goes to a blank screen and I can’t use the WP admin panel unless I delete that plugin from the server.

    Cheers,

    Justin

    Odd, I’ve used it ok on versions from 1.5 onwards. Have you checked to see if there are any whitespaces in the plugin file?

    @fj,
    Check out those links in the post below:
    https://www.ads-software.com/support/topic/31491#post-177815

    Thread Starter functionjunkie

    (@functionjunkie)

    Ian,

    Hmmm, never thought of that actually. I will take a look and post back later.

    Moshu: Thanks, I will check that out as well.

    Cheers!

    Justin

    Thread Starter functionjunkie

    (@functionjunkie)

    Ian,

    I figured out what it was…

    I found this code snippet


    ' if ($query->is_home) {
    if (preg_match("/posts_per_page=/", $query_string)) {
    $query_string = preg_replace("/posts_per_page=[0-9]*/"
    ,"posts_per_page=$num_posts_on_home"
    ,$query_string);
    } else {
    if ($query_string != '') {
    $query_string .= '&';
    }
    $query_string .= "posts_per_page=$num_posts_on_home";
    }
    }
    '

    in the perpage.php file, and replacing that with the original code solved the problem… Also, there was some whitespace in there as well, which probably didn’t help things either.

    Either way, TextDrive didn’t like it very much, but it’s fixed now, and it works beautifully! Great work!

    I’ll make sure that I blog about this plugin later today! ??

    Justin

    Viper: Hmmm… Yes, I am telling it to do that, and I certainly don’t fault it for doing what it’s told, however, one would assume that the monthly archive will show all the posts for that month, and ignoring the set number of posts to display.

    What if you had 100 posts that month though? You really want a page 10 miles long?

    And it is displaying all posts for that month, but it’s doing it in a paged format.

    Thread Starter functionjunkie

    (@functionjunkie)

    Viper007Bond: What if you had 100 posts that month though? You really want a page 10 miles long?

    And it is displaying all posts for that month, but it’s doing it in a paged format.

    I see your point… I don’t think I want a page 10 miles long… I certainly wouldn’t expect anyone to scroll that far either. LOL!!!

    Anyways, thanks for the great plugin. Works like a charm!

    Thread Starter functionjunkie

    (@functionjunkie)

    Ian,

    Coming back to this again… Just upgraded to WP 1.5.1.2, and that plugin is not working again… LOL

    Checked the file for whitespace again, and it’s clean.

    <?php
    /*
    Plugin Name: Custom Posts Per Page
    Version: 1.0
    Plugin URI: https://www.ads-software.com/support/6/11211
    Description: Change the number of posts per page displayed for different page types.
    Author: Based on code by rboren & brehaut
    Author URI:
    */
    $posts_per['home'] = 5;
    $posts_per['day'] = 10;
    $posts_per['month'] = 31;
    $posts_per['search'] = 10;
    $posts_per['year'] = 999;
    $posts_per['author'] = 999;
    $posts_per['category'] = 999;
    function custom_posts_per_page($query_string) {
    global $posts_per;
    $query = new WP_Query();
    $query->parse_query($query_string);
    if ($query->is_home) {
    if (preg_match("/posts_per_page=/", $query_string)) {
    $query_string = preg_replace("/posts_per_page=[0-9]*/"
    ,"posts_per_page=$num_posts_on_home"
    ,$query_string);
    } else {
    if ($query_string != '') {
    $query_string .= '&';
    }
    $query_string .= "posts_per_page=$num_posts_on_home";
    }
    }
    } elseif ($query->is_day) {
    $num = $posts_per['day'].'&order=ASC';
    } elseif ($query->is_month) {
    $num = $posts_per['month'].'&order=ASC';
    } elseif ($query->is_year) {
    $num = $posts_per['year'].'&order=ASC';
    } elseif ($query->is_author) {
    $num = $posts_per['author'];
    } elseif ($query->is_category) {
    $num = $posts_per['category'];
    } elseif ($query->is_search) {
    $num = $posts_per['search'];
    }
    if (isset($num)) {
    if (preg_match("/posts_per_page=/", $query_string)) {
    $query_string = preg_replace("/posts_per_page=[0-9]*/", "posts_per_page=$num", $query_string);
    } else {
    if ($query_string != '') {
    $query_string .= '&';
    }
    $query_string .= "posts_per_page=$num";
    }
    }
    return $query_string;
    }
    add_filter('query_string', 'custom_posts_per_page');
    ?>

    Are there any updates to this plugin? Or is WP not liking this plugin for other reasons?

    Thanks,

    Justin

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Monthly Archives Only Showing 5 at a Time’ is closed to new replies.