WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Query Post for 2 Category Pages (19 posts)

  1. ailinalei
    Member
    Posted 3 years ago #

    Hello There,

    I have 2 menu that are category paged:
    Events: http://cakedla.com/wordpress/?cat=5
    Media: http://cakedla.com/wordpress/?cat=11

    I'm trying to figure out the query post to set to view at 5 posts. I used the following code & added the navigation previous/next links at the bottom:
    query_posts($query_string.'&category=5&showposts=11');

    When I added the code above and clicked on next page navi, I get an error/404 page. Is there a php template file I need to add? Please help.

    Thank you so much.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Try:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => 5,
            'posts_per_page' => 11,
    	'paged' => $paged
    );
    query_posts($args);
    ?>
  3. ailinalei
    Member
    Posted 3 years ago #

    This works great! Thank you esmi!

    One more question. I'm working on 2 category pages and they're both using the same archive.php template. How do I make an if function code to use category 11? (if category 5 and if category 11)

    Thanks!!! Almost there!

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Not sure if I understand you correctly...

  5. ailinalei
    Member
    Posted 3 years ago #

    I have 2 categories using the same archive.php file. What code is needed to add category 11?

    Media page (category 11) currently has the same post as Events page (category 5):
    Events: http://cakedla.com/wordpress/?cat=5
    Media: http://cakedla.com/wordpress/?cat=11

    How to fix category 11 page?

    Sorry, I'm still learning all this. Thanks for helping.

  6. esmi
    Forum Moderator
    Posted 3 years ago #

    All of your categories will be using archive.php - including category 11. I'm not sure what there is to "fix".

  7. ailinalei
    Member
    Posted 3 years ago #

    I've tried using this code but doesn't work in archive.php.

    <?php
    
    if ( is_category('5') || $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    'cat' => 5,
    'posts_per_page' => 3,
    'paged' => $paged
    );
    query_posts($args);
    
    } elseif ( is_category('11') || $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    'cat' => 11,
    'posts_per_page' => 3,
    'paged' => $paged
    );
    query_posts($args);
    ?>

    Please let me know if there are codes similar to the one above. If not fixable, then I'll just give up on it.

    Thanks for helping! :)

  8. esmi
    Forum Moderator
    Posted 3 years ago #

    Is this what you were after?

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if ( is_category('5') {
        $args= array(
            'cat' => 5,
            'posts_per_page' => 3,
            'paged' => $paged
        );
    } elseif ( is_category('11') {
        $args= array(
            'cat' => 11,
            'posts_per_page' => 3,
            'paged' => $paged
        );
    }
    query_posts($args);
    ?>
  9. ailinalei
    Member
    Posted 3 years ago #

    Yes, but I got parse error. I think we're close but it's alright, I think it isn't fixable. Thank you thank you thank you though for taking your time in helping me! =)

  10. esmi
    Forum Moderator
    Posted 3 years ago #

    I missed some closing brackets (I'm always doing that!):

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if ( is_category('5') ) {
        $args= array(
            'cat' => 5,
            'posts_per_page' => 3,
            'paged' => $paged
        );
    }
    elseif ( is_category('11') ) {
        $args= array(
            'cat' => 11,
            'posts_per_page' => 3,
            'paged' => $paged
        );
    }
    query_posts($args);
    ?>
  11. ailinalei
    Member
    Posted 3 years ago #

    Awesome! Almost there...I think we're just missing a little bit of coding for cat 11. When I clicked on older entries, I get the 'page not found'.

    Thank you!!!

  12. esmi
    Forum Moderator
    Posted 3 years ago #

    Try:

    <?php
    if( is_category('5')  || is_category('11') ) {
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        if( is_category('5') ) $catid = 5;
        elseif( is_category('11') ) $catid = 11;
        $args= array(
            'cat' => $catid,
            'posts_per_page' => 3,
            'paged' => $paged
        );
        query_posts($args);
    }
    ?>
  13. ailinalei
    Member
    Posted 3 years ago #

    I still get 'page not found' when clicking on elder entries for cat 11. :/

  14. esmi
    Forum Moderator
    Posted 3 years ago #

    If it works for 1 category, then it should work for all/any category. Perhaps it is where/how you are using this code that is the issue?

  15. ailinalei
    Member
    Posted 3 years ago #

    hmmm...this is the code in the archive.php file:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Not really sure why it won't work.

  16. esmi
    Forum Moderator
    Posted 3 years ago #

    The code should work.

  17. ailinalei
    Member
    Posted 3 years ago #

    i wish it did.

    http://cakedla.com/wordpress/?cat=11&paged=2 page not found.

  18. manuelmasia
    Member
    Posted 3 years ago #

    Is anybody able to solve this problem?
    There is no way (since WP 3) to overwrite global posts_per_page.

  19. esmi
    Forum Moderator
    Posted 3 years ago #

    @manuelmasia: Please post a new topic.

Topic Closed

This topic has been closed to new replies.

About this Topic