• 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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Leovenous

    (@leovenous)

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

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

    Resources:
    The Loop
    The Loop in Action

    Thread Starter Leovenous

    (@leovenous)

    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…

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    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.

    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/

    Thread Starter Leovenous

    (@leovenous)

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Multiple Loop Floop’ is closed to new replies.