Forums

multiple queries on one page? (6 posts)

  1. warpdesign
    Member
    Posted 2 years ago #

    Hi, I'm building a template that has a category, sub-category and post excerpts in the side bar. I created the part of the sidebar that lists the excerpt of the current category like so

    <?php query_posts("cat=$cat"); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink() ?>" class="more"> <?php the_excerpt(); ?></a>
    <?php endwhile; ?>
    </li>

    It was working fine as long as I didn't do anything to the main query on the page. But now I only want to show the most recent post on the category page so I put this line at the top of the main file

    <?php query_posts("showposts=1"); ?>

    and now the side bar doesn't work. Is there a way to make the two queries not conflict with one another?

  2. vkaryl
    Member
    Posted 2 years ago #

    Maybe start here:

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

    I know there's a way to use more than one query, just not sure right now where the info is....

  3. warpdesign
    Member
    Posted 2 years ago #

    Hmm, thanks for the link but I wasn't able to make any headway. I basically want my side bar to have an excerpt that has nothing to do with the query on the page, so I'm running a second query on it that conflicts with whatever the main query is for the page that is pulling the side bar. Does that make sense?

    How can a start a new query and loop on the sidebar that is seperate from the main one for the page?

  4. vkaryl
    Member
    Posted 2 years ago #

    I feel stupid now, because the info is something I got involved in myself some months back - chalk it up to trying to work while sick?

    Check this thread (be warned: it's fairly long):

    http://wordpress.org/support/topic/83936?replies=41

    You'll see within there exactly how to set up separate queries this way. Now, caveat-time: once you use the loop and queries like this, the previous/next navigation won't work.

    If you can make the query thing work without needing a second loop, it should leave the nav alone.

    And after you read through that, if you want to try it, I have the salient parts in a file; if you want it, say so, and I'll post it to pastebin and return the link.

  5. warpdesign
    Member
    Posted 2 years ago #

    Thanks! It's working now. This page here helped tremendously (for future reference)

    http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

  6. vkaryl
    Member
    Posted 2 years ago #

    Good to hear. Mark this as resolved then, please and thanks?

Topic Closed

This topic has been closed to new replies.

About this Topic