insert <div> in one instance of php loop

The content on the main page of my site is displayed in a box that has the article on the left and other articles in that category in a list on the right. The wordpress main page index is set to create another box immediately underneath the first and so on, for each category I wish to have displayed.

I would like to insert a small div section for video thumbnails after the first content box, then allow wordpress to go back to posting the other content boxes below that. I am just learning php and have been having trouble with this.

Read More

I have added the div, in the appropriate position in the loop, but how can i isolate it to appear only under the first content box ($cat1), rather than all content boxes?

I tried

<?php while($cat1);{
echo '<div id="video"></div>'}
?>

but im just not sure,
Any help would be appreciated.

Thanks

Related posts

Leave a Reply

1 comment

  1. You would just set up a simple counter to handle this, as you know which iteration of the loop you have to add the video section in – the first.

    Before the loop initialise a variable as the counter, set it to zero. In your loop you check if the counter is zero, if so you insert your video code. Then you add 1 to the counter and the video won’t be displayed again.

    <?php $count = 0 ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
        // Your normal loop stuff here
    
        <?php
        if ($count == 0 ) {
    
            echo '<div id="video"></div>';
    
        }
    
        $count++;
        ?>
    
    <?php endwhile; endif: ?>