• Resolved hschull

    (@hschull)


    The posts per page setting is global atm. Setting it to 1, 10 or whatever will affect all postings no matter what. Correct me if I am wrong here…

    I suggest that posts per page is linked to category. This would afaik be a possible implementation without interfering with existing data (?).

    The idea is that I e.g. have one category for long articles. Thus I’d like to publish them on one page each. On the other hand I may also have another category for very short daily comments. Being only a few lines each I may want to publish 10 of them on a single page.

    If I missed an existing discussion on the matter, please point me in the right direction!

Viewing 15 replies - 1 through 15 (of 15 total)
  • you can do this with custom category templates

    Thread Starter hschull

    (@hschull)

    Ok, thanks!
    I found this one:
    https://www.ads-software.com/extend/plugins/posts-per-cat/
    But it doesn’t seem to work properly. Any other suggestion?

    you need to rename category.php to category-id.php where id is the numerical id of the category. After that you need to replace/modify your query.

    <?php
    
    //The Query
    query_posts('posts_per_page=5');
    
    //The Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    content and site stuff here
    
    endwhile; else:
     ..
    endif;
    
    //Reset Query
    wp_reset_query();
    
    ?>
    Thread Starter hschull

    (@hschull)

    I’m sorry but this goes way above what I easily comprehend…
    What goes where? Does this relate to the plugin I suggested or is this a stand-alone hack? I’m lost here…

    Although I easily code HTML/CSS I have no php skills at all. Here I need a step-by-step instruction to every file, line and modification without having to actually understand what I’m doing. Who has the patience?

    This is why I requested a simple ‘post-per-page’ option related to category and available in the user interface.

    Problem is there are hundreds of small features like this that would be useful to include in the core version of wordpress, it just isn’t possible to include them all. if you can’t find a plugin that does what you need you are going to have to plough into the template code. If you can handle html and css you’ll be able to work with php, I didn’t know any when I started using WordPress and just picked it up as i went along.

    If you open your theme folder, find category.php and post the code here I’ll have a look.

    Thread Starter hschull

    (@hschull)

    I am fully aware it is impossible to satisfy every need/wish in the core version.

    I still try out different themes/settings on a local server before I go public.
    ATM I use the Atahualpa 3.4.6 theme because it has so many options…

    Unfortunately I am not able to find the category.php file in the Atahualpa theme folder or in any theme folder. In the wp-includes folder it is present though. Who of us is confused?

    Anyway, if the ”standard” /wp-includes/category.php file applies, you already have access to it.

    I appreciate your effort!

    You need to look in wp-content/themes/your-theme folder. I had a quick look and there isn’t a category.php set with this theme, you can just save your index.php (which is your posts template) as category.php or category-4.php if your custom category has an id of 4.

    this will be the template that is used for this category once you add it to the themes folder.

    you need to add
    <?php query_posts('posts_per_page=10'); ?>
    in the category-id.php page that you have made

    <?php /* The LOOP starts here. Do this for all posts: */
    	while (have_posts()) : the_post(); $bfa_ata['postcount']++; ?>

    which is around line 12. Obviously changing posts_per_page will set the number of posts displayed.

    So to sum up, you need to categories; long, with an id of say 4 and short (id say 5). Then you need category-4.php and category-5.php in your themes folder whith the posts per page set accordingly. You can do an awful lot with query_posts, have a look on the codex https://codex.www.ads-software.com/Function_Reference/query_posts

    Here try this out for me.. ??

    https://codex.www.ads-software.com/User:T31os#Category_Posts_per_Page

    Only tested in a local installation, it’s a very simple plugin but should allow you to work with different post per page settings across themes for category pages.

    Two assumptions are made on my part though, firstly that you’re running PHP5 (requirement due to the way the class has been written), and secondly that your category archive pages (a regular category page that lists posts) is using the category name query var when viewing category pages.

    Rather then worry about those two points above, i’d just suggest you try it, and see if it helps. To install, copy the code, place into a file with a .php extension and save. Upload the file into your plugins folder and activate.

    I’ve been working on the code today(i was bored), so it might well change over time, but that’s where i am at the moment, and figured i’d offer the code… it might help.. ??

    Thread Starter hschull

    (@hschull)

    @gerbilk: I hope you understand that at this point I wish to halt (not end) our discussion and try out the project by t31os_.

    @t31os_: Everything looks great, except that I cannot make it work.
    PHP version is 5.2.11.
    I found the plugin settings and entered the numbers (1 and 10) for my two categories (names are plain ASCII with no 0x20).
    In the standard ‘settings/read’ option I tried 1, 5 and 10 (0 is apparently no valid option). Still only these standard settings take effect.
    Running the WP-theme ‘default’ made no difference.
    What might be the trouble?

    I am prepared to keep on trying. This is because so far the project looks an feels exactly like the plug I desired. If it works that is. ??

    (Note. I run the Swedish version and thus make guesses about names and expressions the English interface.)

    It should work, i’m running it inside my 2.9.2 installation and it works as expected.

    0 – should just be ignored, it’s equal to off.
    1,2,3,4,5 or whatever, should set the posts per page to that limit.

    Click “Help” in the top right and you’ll see i’ve put some information there.

    However as i said before there are a few assumptions on my part.

    Permalinks will be required, or if not, at the least you’ll need to (for the moment), ensure categories are queried using the category name (not the ID).

    example.com/?category_name=catname (non-permalink url)
    example.com/category/catname (pretty permalink url)

    not

    example.com/?cat=1 (non-permalink url)
    example.com/cat/1 (pretty permalink url)

    NOTE: This plugin is translatable, or should be(i purposely put translatable code in – good practice), i’ve not had any opportunity to have anyone test translation for me (and i havn’t done a translation process before myself), but you should in theory be able to make a translation file for the plugin.

    Will see what today brings, and get a newer copy up once i have time to work in some changes.

    As with anything i write, it’s open and free to be used as anyone chooses, so if someone else wants to add or hack anything into the plugin, go ahead (i don’t need credits).

    My test environment:

    OS : WinXP
    WP : 2.9.2 / 3.0beta1
    Apache : 2.2.14
    MySQL : 5.1.44
    PHP : 5.3.2

    Thread Starter hschull

    (@hschull)

    Hi! I updated some software, but that made no difference.
    I run a ”lazy persons” application, MAMP, that provides the complete environment I need.
    Still I have not been able to detect any obvious reason on my side why this plugin should not work. Especially since absolutely everything else works.

    ? I’ve had a look at the included “Help”. Good but made no change.
    ? My category permalinks are verbose lower case within a to z, i.e.:
    example.com/category/catname
    ? I’d be happy to translate this plugin to Swedish, if I can make it work…

    My environment:

    OS: Mac OS X 10.4.11 PPC
    Application: MAMP 1.9, Running as below:
    Apache: 2.0.63
    PHP: 5.3.2
    MySQL: 5.1.44
    WP: 2.9.2

    Thread Starter hschull

    (@hschull)

    To be even more specific…
    In the ‘Posts per category page‘ interface my categories show up both by name (bold, verbose) and by permalink (emphasized, verbose, not by ID#).
    Number of posts per page are set accordingly.

    Try this version please, it’s current, ie. what i have right now, so incomplete/work-in-progress, but more current all the same…

    https://wordpress.pastebin.com/iucaue5a

    I’ve changed things around a bit, so hopefully it’s a bit clearer/easier.

    Try using “Name” for your setup if your URLs for category pages(archives) contains the name.

    Thread Starter hschull

    (@hschull)

    YES!
    This works perfectly, nice job!
    So, this is the exact function I initially asked for. Everything is… nice.
    THANK YOU!

    Now, how can I contribute?

    About translation.
    It is not meant to be hard coded, I suppose.
    On the other hand the concept is not obvious to me.

    (Sorry about the delay, I’ve been busy.)

    Nothing to contribute, my code is given free for anyone to use (appreciate the offer though).

    I’m still playing with the code, but once it’s complete (in my mind, ie. i’m happy with it), i’ll be posting it up on my blog (click my name for link).

    Translation, don’t worry too much, i’ll work out how to test that at some point.

    Happy i could help… ??

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Different number of posts per page by category’ is closed to new replies.