WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Loop Floop (7 posts)

  1. Leovenous
    Member
    Posted 7 years ago #

    I've been digging through the documentation for days and I guess I'm just not getting it. I have a page from a template I made that calls a category-specific loop, then later calls a page-specific loop, but in the latter it inserts the post from the former.

    http://www.globalencounter.net/registration

    The first loop calls a category and uses their titles for the listbox. Then the page loop calls that page "registration" or "page_id=7" for my fake sidebar. The post in there now is the content of one of the category posts. Here is my code for the first loop:

    <?php query_posts('category_name=upcoming-trips'); ?>
    <? while (have_posts()) : the_post(); ?>
    <option value="<?php the_title(); ?>"><?php the_title(); ?></option>
    <?php endwhile; ?>

    And here is the second query... its not a loop cause a page has only one theoretical "post", right?

    <?php query_posts( 'page_id=7' ); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <div class="entry">
    <?php the_content(); ?>
    </div>
    </div>

    I assume there is something stuck in a global that is not being replaced by the second query, but how to get out of this one I can't figure out.

  2. Leovenous
    Member
    Posted 7 years ago #

    I'm still trying to work through this. Kind of in the read-documentation-for-the-tenth-time-and-blindly-experiment mode.

  3. MichaelH
    Member
    Posted 7 years ago #

    Might try <?php rewind_posts(); ?> before that 2nd query.

    Resources:
    The Loop
    The Loop in Action

  4. Leovenous
    Member
    Posted 7 years ago #

    Ummm, thanks but, yeah that's what I've been reading and reading (I have a loose grasp on PHP).

    What gets me is; it is normal for me to run 2.. 3.. 4 loops on a page, and they don't interfere with each other. But something about trying to call the Page data, either by have_post or by query_posts('page_id [or page]') doesn't sit right.

    I may break down and put the page content in a post and call it in specifically. Arg...

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    And here is the second query... its not a loop cause a page has only one theoretical "post", right?

    Wrong. A Loop must be a loop. And yes, even Pages need Loops to display their content. Why? Because Pages are nothing more than special forms of Posts. A Page is a Post with a flag on it that says "page".

    So, try this instead:

    <?php query_posts( 'page_id=7' ); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <div class="entry">
    <?php the_content(); ?>
    </div>
    </div>
    <?php endwhile; ?>

    Now, while I say that, I'm also lying. :) You don't really have to have it in an actual Loop. What's doing the work you're actually wondering about here is the call to the_post().

    However, it's a lot simpler if you just make Loops as actual loops. Don't try weird variations. That way lies madness.

  6. moshu
    Member
    Posted 7 years ago #

    Since I am not a coder, for me the easiest way to include the content of a Page/post in a template is to use this plugin:
    http://guff.szub.net/2005/01/27/get-a-post/

  7. Leovenous
    Member
    Posted 7 years ago #

    Wow. Did you know you are very right sometimes Mosh? I had wondered about the_post but wasn't able to gain enough understanding on it to see the light.

    Okay, well after a few days of banging my head its nice to be moving forward again. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic