WordPress.org

Support

Support » How-To and Troubleshooting » Writing something in the loop after the first post

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 nยบ 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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t!

    Instead of <?php $a = $a++; ?> try <?php $a++; ?>, not sure if it will fix your problem, but to my understanding the first $a is unnecessary, or maybe wrong even.

    Thanks for the reply! That’s the same, like doing a count, attributing the $a the value of the $a plus 1… But I tried and no… that doesn’t work… :/

    Ups…I was wrong..! My friend changed the template I was using on that page and when I tried the $a++ I thought it was not working… but the $a++ worked!! I thought it was the same as what I had… but now that it worked I just saw the error I was doing… $a++; is only the same as $a = $a + 1; like I sad in the last comment and, still, I didn’t notice… ๐Ÿ˜›

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Writing something in the loop after the first post’ is closed to new replies.
Skip to toolbar