• Resolved raj080288

    (@raj080288)


    Hi,

    I’m creating a theme from scratch. I have a one page parallax website. i have 5 posts which are being used as pages to create the single page website look (scrolling website).

    Out of the 5 posts, I want to add div tags to 2 of the posts. Does anyone know how to go about that one. I have been trying to work this one out for ages but cat seem to find a solution.

    I have it working but its not correct, the way Ive done it is that it ends up adding div tags for every post even if that post does not require it.
    This is what I have so far:

    <?php
    		query_posts('posts_per_page&order=ASC');
    			while(have_posts()) : the_post(); ?>
    
    			<section class = "container" id="<?php echo get_the_title(); ?>">
    				<article class = "row <?php echo get_the_title(); ?>">
    					<?php the_content(); ?>
    					<?php for($i=0; $i<5; $i++){
    					$x = $i;
    					?>
    
    					<div id="<?php echo get_the_title(). $x; ?>"></div>
    					<?php } ?>
    				</article>
    
    			</section>
    
    	<?php endwhile; wp_reset_query(); ?>

    Raj

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey there raj080288,

    Hope you’re well! ??

    Get the code here: https://gist.github.com/calvincanas/7c7f045f13223d8672fb

    The way I tackled this is by creating a $counter = 1; variable which increase every iteration.. Then if I want to show the extra div in 2nd and 4th iteration – I create an if-condition statement which checks if the $counter value is 2 or 4. If yes, then it will produce the extra div.

    Hope it helps! ?? Looking forward for your reply! ??

    Take care,
    Calvin

    Thread Starter raj080288

    (@raj080288)

    Hi Calvin, thanks for your answer it works great. The only problem is I want 2 divs with the same name on the first page and 2 divs with same name on second page. Right now its adding the extra 2 div with the same name to both pages.

    Thanks,

    Raj

    Thread Starter raj080288

    (@raj080288)

    Hi Calvin,

    I sorted this now, just had to do another if and end if. Thanks for your help. You’re truly a star!!!

    Thank yo very much,I appreciate all your help.

    Raj

    Hey there Raj,

    Glad it’s working for you! ??

    I suggest you mark this thread as resolved so other members with the same issue can see that this ticket contains an answer that maybe a possible solution for their issue.

    Take care,
    Calvin

    Thread Starter raj080288

    (@raj080288)

    thanks!!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do i add div tags for specific posts only?’ is closed to new replies.