I have a question. This is my loop:


$args = array( 'post_type' => 'homepage_section', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();?>


if( !isset( $row_num ) ) $row_num = 1; // at first $row_num does not exist so create it and make uneven (start with 1)
  $row_class = (++$row_num % 2) ? 'right' : 'left'; // then check whether $row_num is odd or even and assign it the corresponding class name


<!-- One -->
<section id="one" class="main style2 dark fullscreen <?php echo $row_class;?>" style="background: url(<?php
        $varable_holding_img_url = the_post_thumbnail_url('full');
         echo $varable_holding_img_url; ?>);">
            <div class="content box style2">
                    <h2><?php echo  the_title();?></h2>
                <p><?php echo  the_content(); ?></p>
            <a href="#two" class="button style2 down anchored">Next</a>



There is an href in the bottom, and I want to make href = "#one,two,three" dynamically change. Can anyone help me?

  • 'Dynamically change' can mean anything, even random assignment. What are you trying to achieve? What have you tried so far? – cjbj Oct 7 '16 at 8:17
  • Hi, Suppose there is a while loop. and the div is <div id="one">. I want to change the id dynamically like, <div id="one">, <div id="two">, <div id="three"> How is it possible using php – nadzhq Oct 8 '16 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.