• Hello,

    By using the WordPress loop in my homepage it is prevent the php if statement

    <?php if (is_home()) { echo "Hello"; } else { } ?>

    from working later on in my footer. I can’t possibly understand why this is. My code for the WordPress loop and my footer are the following.

    <?php if (is_home()) { ?>
    
    	<div id="content">
      		<div class="wrapper">
    
        		<div id="col1">
                	<div id="col1_top">
                    	<div class="container">
                        	<h5>Latest Notices</h5>
                        </div>
                    </div>
                    <div id="col1_bod">
                    	<div class="container">
                        	<?php query_posts('category_name=Notice&showposts=4'); ?>
                            <?php while (have_posts()) : the_post(); ?>
                      		<div class="col_item">
                        		<div class="col_item_title">
                            		<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
                           		</div>
                            	<div class="col_item_content">
                            		<p><a href="<?php the_permalink(); ?>"><?php the_content('Continue Reading...'); ?></a></p>
                            	</div>
                            </div>
                            <?php endwhile; ?>
                        </div>
                    </div>
            	</div>
    
                <div id="col2">
                	<div id="col2_top">
                    	<div class="container">
                        	<h5>Latest Projects</h5>
                        </div>
                    </div>
                    <div id="col2_bod">
                    	<div class="container">
                        <?php query_posts('category_name=Project&showposts=4'); ?>
                            <?php while (have_posts()) : the_post(); ?>
                      		<div class="col_item">
                        		<div class="col_item_title">
                            		<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
                           		</div>
                            	<div class="col_item_content">
                            		<p><a href="<?php the_permalink(); ?>"><?php the_content('Continue Reading...'); ?></a></p>
                            	</div>
                            </div>
                            <?php endwhile; ?>
                        </div>
                    </div>
            	</div>
    
                <div id="col3">
                	<div id="col3_top">
                    	<div class="container">
                        	<h5>New Scientist Health</h5>
                        </div>
                    </div>
                    <div id="col3_bod">
                    	<div class="container">
                        	<div class="col_item">
                        		<?php echo SimplePieWP('feed://feeds.newscientist.com/health'); ?>
                           	</div>
                        </div>
                    </div>
            	</div>
    	</div>
    </div>
    
    <?php } else { } ?>

    Which stops this from working.

    <?php if (is_home()) { ?>
            <div class="caption">
            	<h6 class="caption"><span>Skip the bus? Try walking, or cycling? It's certainly healthier, and better for the enviroment.</span></h6>
            </div>
    
            <div class="motive">
            	<img class="fmo" src="http://healthyeatingandliving.org.uk/wp-content/themes/heal/image/background_bus.png" alt="" />
            </div>
    		<?php } else { } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • hi

    instead of is_home() try using is_front_page(). Its not intuitive but that is how you designate the homepage. is_home() actually refers to the posts page.

    If it still does not work, set a variable after you enter the first loop

    <?php if (is_front_page()) { ?>
    ADD-->   $front_page = true;
    	<div id="content">
      		<div class="wrapper">
    
        		<div id="col1">
                	<div id="col1_top">

    and change your lower code like this

    <?php if ($front_page) { ?>
         <div class="caption">
            <h6 class="caption"><span>Skip the bus? Try walking, or cycling? It's certainly healthier, and better for the enviroment.</span></h6>

    Thread Starter georgerobbo

    (@georgerobbo)

    hi

    instead of is_home() try using is_front_page(). Its not intuitive but that is how you designate the homepage. is_home() actually refers to the posts page.

    If it still does not work, set a variable after you enter the first loop

    Hello,

    I’m afraid neither of those solutions work. There is something with my WordPress loop which is interfering with the IF statement.

    Thread Starter georgerobbo

    (@georgerobbo)

    I’ve found the solution. It involves resetting the WordPress loop using

    <?php wp_reset_query(); ?>

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