1

I want to generate the following code automatically within a Wordpress loop:

<ul class="content">
  <li class="box it" data-id="id-1" data-type="it">
    <h1>No# 01</h1>
  </li>
  <li class="box medical" data-id="id-2" data-type="medical">
            <h1>No# 02</h1>
  </li>
  <li class="box education" data-id="id-3" data-type="education">
            <h1>No# 03</h1>
  </li>
</ul>

What I want it to have my php code from within the Wordpress loop to echo "data-id="+(auto incremented number as in the above instance).

How will I construct the loop?

1 Answer 1

2

try

<ul class="content">
 <?php for($i=1;$i<some_num;$i++) {?>
 <li class="box it" data-id="id-<?php echo $i; ?>" data-type="it">
    <h1>No# <?php echo $i; ?></h1>
  </li>
  <?php  } ?>
</ul>
Sign up to request clarification or add additional context in comments.

2 Comments

you have a typo there for($=1
I didn't downvote your answer. And I don't know why someone should.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.