• I asked this some time back bur I had no luck in finding a solution.
    Is there a plugin or hack that lets you set the number of the posts per page, according to the category that they belong? For example I have a category named “blog” and a category “essays”. I want the category “blog” to display 10 posts per page and essays to show only 3 posts per page. How can I do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’d suggest this version of the plugin Lorelle references above:

    https://rephrase.net/miscellany/05/perpage.phps

    You’ll need to modify it a bit to fit your needs. First, set the various $posts_per variables to the # of posts per page you want displayed for each type (including category). Then in the custom_posts_per_page function, change the global line to this:

    global $cat, $posts_per;

    Farther into the function you’ll find where the category query type is tested for:

    } elseif ($query->is_category) {
    $num = $posts_per['category'];

    Modify it like so:

    } elseif ($query->is_category) {
    if($cat == 10)
    $num = 10;
    elseif($cat == 20)
    $num = 3;
    else
    $num = $posts_per['category'];

    Make sure to set the appropriate numeric category ID for each $cat == #.

    This should do just what I want – but I can’t make it work.

    The perpage.phps works fine, but setting $num to anything other than $posts_per[‘category’] doesn’t seem to work – I just get the default number of posts on every category.

    Should the variable name definitely be $cat, or should it be something else?

    Ok, in case anyone else has this problem, I got mine to work by changing the If statement slightly like this:

    if($cat==’1′)
    {$num = 70;}
    if($cat == ‘2’)
    {$num = 70;}
    if ($cat > ‘2’) // Changed from else, which didn’t work
    {$num = $posts_per[‘category’];}

    I uploaded and installed user meta and when I activated it blew up my site. Perhaps I should have really researched whether it was compatible with 2.0.

    I deleted the file and reuploaded my entire site. Now I get this error.

    It doesn’t look like you’ve installed WP yet. Try running install.php.

    But of course I cant run the install.

    Any help on getting my site back?

    I’d really like this plugin if I can get it to work. It’s perfect for my needs.

    I’d really appreciate any help in figuring how to fix my site.

    Shun shifu

    Shun, I am still using this same gadget on my site, now upgraded to the latest version of WordPress, and it does still work.

    It sounds as though you had some minor problem with the exact php coding of the plugin file, then deleted your wp-config.php file when you deleted the entire site.

    Do you have a backup of your config file? Alternatively, can you resurrect your wp-config.php file from the provided wp-config-sample.php?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Number of displayed posts per page according to category’ is closed to new replies.