Writing something in the loop after the first post
-
Hello everyone!!
I’m having this problem that is suposed to be really easy and I don’t know why it’s not working… I’m trying to involve all the posts after the first one in a div to be hidden and collapsable…<?php query_posts( 'showposts=5' );?> <?php $a = 0; ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $a = $a++; ?> <?php if ($a == 2) : ?> <span class="collapseomatic colomat-visited" id="id6158" alt="show more news" title="show more news">+</span> <span id="swap-id6158" style="display:none;">—</span> <div id="target-id6158" class="collapseomatic_content" style="display: none; "> <?php else: endif; ?> <?php the_content(); ?> <?php endwhile; else: endif; ?> <?php if ($a > 2){ echo "</div>"; } ?>
For that I created a variable $a that is going to be equal to the number of the current post in the loop, and when the post is the no 2 I make it write the button to hide and show the rest of the content and open the div that will hide the content…than, after all the loop has finished, I close the div.
What is appearing on the page is the content as if there was no variable $a and if else to write the enclosure div.
Can someone understand this? O.o
Thanks in advance!
- The topic ‘Writing something in the loop after the first post’ is closed to new replies.