WordPress.org

Ready to get started?Download WordPress

Forums

Issue with posts_per_page & category combination (14 posts)

  1. gunterr
    Member
    Posted 4 years ago #

    Been struggling with this for a few hours now, I hope I'm not overlooking an older topic about this or anything.

    What I want to do is fairly simple actually

    I just want to show one post of a specific category. I'm using this code.

    <?php
    query_posts('cat=3&posts_per_page=1');
    // the Loop
    while (have_posts()) : the_post();
    the_content('Read the full post ยป');
    endwhile;
    ?>

    Now, both 'cat=3' & 'posts_per_page=1' work perfectly fine, but when using them in combination the posts per page limit just won't work. (While the cat-part still does its job)

    I have also tried 'showposts=1', which again works separately but not in combination with the 'cat=3'

    Thanks for taking the time!

  2. MichaelH
    Member
    Posted 4 years ago #

    Example of proper pagination:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=1&posts_per_page='.get_option('posts_per_page').'&paged=' . $paged);
    ?>
  3. gunterr
    Member
    Posted 4 years ago #

    But how do I specify now that I just want it to show 1 post?

    And any explanation why they work separately but not when used together.

    Thanks for the quick reply!

  4. MichaelH
    Member
    Posted 4 years ago #

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=3&posts_per_page=1&paged=' . $paged);
    ?>
  5. gunterr
    Member
    Posted 4 years ago #

    Thanks, I figured that was what you meant and already tried that but it seems to give the exact same result as before. Works without the cat=3 but not in combination with it ... Thus the posts_per_page seems to be ignored ... any ideas on what may be the problem?

  6. MichaelH
    Member
    Posted 4 years ago #

    Look at the WordPress Default theme's wp-content/themes/default/index.php and make sure you are using the correct structure for using the template tag, previous_posts_link() and next_posts_link().

    Related plugin:
    http://wordpress.org/extend/plugins/custom-post-limits/

  7. gunterr
    Member
    Posted 4 years ago #

    edited: thought it worked, but was mistaking

  8. gunterr
    Member
    Posted 4 years ago #

    Everything seems to work perfectly as expected. But every time I try using both cat=4 and posts_per_page, the category just gets ignored. I've tried about everything by now ... Any idea on what the problem may be?

    (Don't think it would matter, but I am using the Carrington framework)

    the help is much appreciated

  9. DarkLour
    Member
    Posted 4 years ago #

    I get the same problem. and im using Carrington as well, so that must be the real problem lol

  10. nickohrn
    Member
    Posted 4 years ago #

    If you are still struggling with this problem, I have a solution for you. I am using the Carrington theme as well and can confirm this is a bug with the theme.

    If you look in carrington-core/ajax-load.php on line 88, there is a function which overrides the posts_per_page parameter when you're trying to call query_posts with a category. You can remove this filter completely with the following:

    remove_filter('pre_get_posts', 'cfct_posts_per_archive_page');

    At that point, everything should work for you again.

  11. Jon W
    Member
    Posted 4 years ago #

    where do you type that? In the ajax-load file or in the index?

  12. Jon W
    Member
    Posted 4 years ago #

    Sorted it, now have

    `query_posts($args);
    remove_filter('pre_get_posts', 'cfct_posts_per_archive_page');
    query_posts('cat=-82&posts_per_page=16');`

  13. IMD
    Member
    Posted 4 years ago #

    I am having this same problem. I built my own theme based off of the default theme files. Does anyone know of a reason this wouldn't work using the default theme? I looked for something like what was mentioned above, but couldn't find anything.

  14. sood_sumit19
    Member
    Posted 3 years ago #

    Thanks your help. I wasted my 5 hrs to sort this out.

Topic Closed

This topic has been closed to new replies.

About this Topic