Support » Fixing WordPress » Pages – using the loop and query_posts

  • Hi.

    I have created a page called ‘articles’ (id=2).

    On this page I would like to have the page title and body, I would also like to query all posts from a particular catagory, AND I need to run list_pages() and have it list the ‘articles’ page as being current. whew!

    If I use query_posts() to try and pull in all posts from my category, it breaks list_pages() knowing that this is the current page and applying the current_page_item class the the li tag.

    I have done some digging and it turns out this is because apparently query_posts() resets the query object? (whatever THAT means) 😉 Essentially, I believe that query_posts is doing something to list_pages preventing it from knowing that the page its on is the current one.

    Any help on how to pull specifc post catagories into a page would really help. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ok, I figured it out!

    On this page:
    Scroll down, you’ll see this:

    <?php $my_query = new WP_Query(‘category_name=special_cat&showposts=10’); ?>

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <!– Do special_cat stuff… –>
    <?php endwhile; ?>

    <?php rewind_posts(); ?>

    What you want to do is build your own query, then reweind posts to reset the query object so that list_pages doesn’t break.

    actually, another method is to simply ‘store’ into variables the bits about the initial query (such as the categories) before starting your custom query. Then refer to that anywhere later on the page.


    Thanks david. I’m not sure what that means though. I’m not a programmer, and so my level of understanding is very basic. Maybe you could provide an example?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pages – using the loop and query_posts’ is closed to new replies.