WordPress.org

Ready to get started?Download WordPress

Forums

Pagination issue (7 posts)

  1. akela
    Member
    Posted 8 years ago #

    Hello!

    I noticed that if I exclude one(or more) category from the main loop in Index.php file then posts for excluded category(ies) not appearing on main page (as expected) ,but still considered by loop when creating links to NEXT and PREVIOUS pages. For example i have 10 posts and number of posts to show is set in admin as 5. Also , my 2 recent articles are in excluded (from the loop in INDEX.PHP) category. Then when on home page i have only 3 posts and link to NEXT page - having 5 posts. My question is : is it a bug? or i miss something? or this is normal.. I do not use any other loops in INDEX.php file.
    Thanks

  2. Kafkaesqui

    Posted 8 years ago #

    If using in_category() to exclude categories, it's working as it should.

    At issue here is how in_category() is able to test against a post, which is only after it resides in the present post query or object. It has no ability to retrieve yet another post when one is passed over. So if a page displays ten posts but three fall within an excluded category, only seven are displayed. It's a basic math problem: 10 - 3 = 7.

    A way around this is to exclude the category from the initial post query itself. For that, see the info on query_posts():

    http://codex.wordpress.org/Template_Tags/query_posts

  3. akela
    Member
    Posted 8 years ago #

    I did so - used query_posts() soon after realized that maybe i want too much. But with this query i can not use NEXT PREVOUS links either - pressing on them returns me the same 1st page. At last i decided to drop the idea and use a model of static, in terms of pagination, front page with 10 posts.
    At the moment i'm happy but question with query_posts() pagination is still there. Im using query_posts('cat=1,4'); - and also played with posts_per_page= parameter, showposts= . None of them make second page. Strange thing is that browser shows address of a second page - ....?page=2 But the page actually shown is first.

    Thanks for help

  4. Kafkaesqui

    Posted 8 years ago #

    My top secret method for slipping paging into query_posts():

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("paged=$paged&cat=1,4");
    ?>

  5. akela
    Member
    Posted 8 years ago #

    It works....
    In my heart i knew that there is a way - WordPress is brilliant software coded by smart guys and supported by very helpful people :)

    People, pagination problem is over and gone.

    Thanks to Kafkaesqui !

  6. akipfer
    Member
    Posted 7 years ago #

    Kafkaesqui, you are my hero! :) That is EXCACTLY the piece of code I was looking for. Thanks so much!

  7. Dalton
    Member
    Posted 7 years ago #

    Yup - this worked for me, too. Thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.