Need help with Wordpress Query

Discussion in 'PHP' started by Austars, Mar 25, 2009.

  1. #1
    Hello,
    I'm running wordpress on my site with the theme The Morning After. I understand that wordpress typically has a standard query of its own, however this theme uses a custom query to make its frontpage look a certain way. I'm fine with it, however I want it to be able to have a page 2. How do I modify it?

    ?php $the_query = new WP_Query('cat=-' .$catid. ',-' .$catid2. '&showposts=5&offset=1&orderby=post_date&order=desc');
    			
    
    ...
    
    
    while ($the_query->have_posts()) : $the_query->the_post();
    Code (markup):

     
    Austars, Mar 25, 2009 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    A bit unsure as to what you are asking here - do you want to make another page, as a separate page on the blog? For instance (given that it is the site in your signature), having a "go to page 2" or something like that?

    If so, it should be enough to just make another page on the blog, maybe you'll need to add the menu-structure (I don't know the theme) and use the same template for the second page?

    But maybe I've misunderstood what you want?
     
    PoPSiCLe, Mar 25, 2009 IP
  3. aaron d.

    aaron d. Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you use the query:

     $the_query = new WP_Query('cat=-' .$catid. ',-' .$catid2. '&showposts=5&offset=1&orderby=post_date&order=desc'.'&paged='.$paged);
    Code (markup):
    it will automatically page the query based on the page number passed
    through the url eg "/page/4"

    However, this doesn't work with the “post_nav_link” function because it
    only checks the $wp_query variable. To get around this you have to
    trick the function by switching $wp_query on it. Add the first block
    before your custom loop and the second after to achieve this effect.

    <?php //query_posts('paged='.$paged);
        $temp = $wp_query;
        $wp_query= null;
           $wp_query = new WP_Query();
           $wp_query->query('cat=-' .$catid. ',-' .$catid2. '&showposts=5&offset=1&orderby=post_date&order=desc''.'&paged='.$paged);
        ?>
    Code (markup):
    <?php $wp_query = null; $wp_query = $temp;?>
    Code (markup):
    Then just remove all the "$the_query->"s mucking up your template file.
     
    aaron d., Mar 26, 2009 IP