using if statement to load different “the loop”
-
I have three pages that display three different categories.
1. our products
2. where to buy
3. pressWhen each page loads I want to show the category that relates to the page. In each case the way I layout the image and title is different. I thought I would use an if statement to see what page was loaded and then load the appropriate loop using an include.
This works great from the home blog page (aka products page) but not from the press page?? The include loads but after the second if statement it fails. Why?
The index page:
<div id="mainContent"> <!-- *note: home a.k.a. the blog page has been changed to the product page using the word press administrator but it is still refered to as home in the scripting--> <?php // generate info appropriate to the page being displayed if (is_home()) { include( TEMPLATEPATH . '/theLoop_poducts.php' ); include( TEMPLATEPATH . '/theLoop_where_to_buy.php' ); include( TEMPLATEPATH . '/theLoop_press.php' ); <!-- this works like a charm --> } elseif (is_page()) { // we're looking at a static page. Which one? if (is_page('in-the-press')) { // our press page. echo "<p>This is in the press!</p>"; include( TEMPLATEPATH . '/theLoop_press.php' ); } else { // catch-all for other pages include( TEMPLATEPATH . '/theLoop.php' ); } } else { // catch-all for everything else (archives, searches, 404s, etc) echo "<p>Pedro offers you his protection.</p>"; include( TEMPLATEPATH . '/theLoop.php' ); } ?> </div><!--end of mainContent-->
The include page:
<!-- the loop if category is "product" then display else say sorry no post vailable --> Product page has loaded <!-- Start the Loop. --> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- The following tests if the current post is in category Products. --> <!-- If it is, the div box is given the CSS class "products". --> <?php if ( in_category('products') ) { ?> <div class="product"> <!-- Display the Title as a link to the Post's permalink. --> <a href="<?php the_permalink(); ?>"> <div id="title"><?php the_title(); ?></div> <!-- Display the Post's Content in a div box. --> <div class="entry"><?php the_content(); ?></div> </a> </div> <!-- closes the first div box --> <?php } ?> <!-- Stop The Loop (but note the "else:" - see next line). --> <?php endwhile; else: ?> <!-- The very first "if" tested to see if there were any Posts to --> <!-- display. This "else" part tells what do if there weren't any. --> <p>Sorry, no products available.</p> <!-- REALLY stop The Loop. --> <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘using if statement to load different “the loop”’ is closed to new replies.