• Hi Guys,

    I am trying to have two seperate categories on my homepage, so i can show only certain posts in one column, and others in the other.

    However i only want the certain posts to show on the homepage so i have tried using a IF statement but it is giving me an error when used with the loop.

    Any ideas would be most appreciated.

    Thanks

    <?php
      if (is_home())
        echo '<div>
    
        <?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<div class="header">
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> <span class="date"><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></span>
    					<span class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
    				</div>
    
    </div>'?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • asigno,

    Hi, There are a couple reasons why the code above would generate errors. The Main reason would be the fact that you nested the <?php tags. This will always cause the page to break…

    <?php
      if (is_home())
        echo '<div>
    
        <?php

    Please Try the code below:

    <?php // Start of "The Loop"
    	if (have_posts()) :
    		while (have_posts()) :
    			the_post();
    ?>
    
    <?php if ( is_home() ) : ?>
    	<!-- Insert Special Code For Homepage Here -->
    <?php else : ?>
    	<!-- Code for all other pages -->
    <?php endif; ?>
    
    <?php // End of the Loop
    	   endwhile;
    	endif;
    ?>

    Excellent thanks ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Homepage IF statement, to show only certain DIV containing LOOP’ is closed to new replies.