WordPress.org

Ready to get started?Download WordPress

Forums

Three loops on front page not behaving... (2 posts)

  1. squidelephant
    Member
    Posted 5 years ago #

    I am developing a site, http://www.counterculturecollective.com. It's the first time I've built a site on wordpress that is more than just a portfolio or brochure. For the site, there are three categories of pots that need to be displayed on the front page:
    -blog posts
    -events
    -featured artists
    As you can see, blog and events display where they're supposed to. But when I publish a featured artist post, it shows up in all three loops. Each area is only supposed to show that particular category.

    here's the code: http://wordpress.pastebin.ca/1364621

    At first I was just using the codex article on multiple loops. Then I found perishable press' triple loops tutorial, and I followed it to the letter - it's exactly what I want. Unfortunately, it didn't work, and I have the problem I described above.

    Also, in all this I've had a very hard time finding the ID number of each category. It's not listed anywhere when I go to edit categories in the dashboard - I have to find it by going through /?cat_id= links until I find the one I'm looking for. Where is it supposed to be? Is my wordpress broken somehow? I used the tag to category converter importing posts from a blogspot, but then it gave me 140ish categories that should have just been tags. So I deleted all those categories and now my category count starts at 140. Could this be the source of my problem?

    Also, is there another way to accomplish what I'm trying to do, say with plugins? Featured artist and Blog posts both just display excerpts if the most recent post and link to the appropriate archive page. Classes is the only section that displays more than one post at a time.

    Thanks for your time, y'all.

  2. stvwlf
    Member
    Posted 5 years ago #

    Hi

    If I am reading your first loop code correctly, its not doing anything

    // the first loop
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php if ( in_category('class') && is_home() ) continue; ?>
       <?php if ( in_category('featured') && is_home() ) continue; ?>
    <?php endwhile; ?>

    You are looping through the posts and taking no action on any of them. Continue means go back to the top of the loop and process the next post. So if its not in either call or featured it reaches the endwhile and does the same thing - loops back to the top.

    When it has processed all the posts (doing nothing to them) it then exits the loop and falls through and executes the display post code beneath the loop one time (probably on the oldest post in the bunch) and then reaches the 2nd loop's code and executes it.

    You should drop this

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php if ( in_category('class') && is_home() ) continue; ?>
       <?php if ( in_category('featured') && is_home() ) continue; ?>
    <?php endwhile; ?>

    and have it more like this

    <?php query_posts('cat=987'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    .... post display stuff goes here ...
    <?php endwhile; ?>

    as far as category ID codes, yes it is not set up well now. The place you can see the cat ID code is on the cat edit page - point at a cat name and look in the lower left corner of the browser, in the status bar line - you will see a URL there - the very right end of that URL displays the Cat ID #.

Topic Closed

This topic has been closed to new replies.

About this Topic