Assuming you are playing around with Wordpress, posts are being rendered within while loop.
Probably your post template is beign fetched by another file by using
get_template_part
#1 Use css
Use css to apply custom stylesheets. Apply custom class to your divs, like .customdiv
, and then style them by using div.customdiv:nth-child(x)
. No further modifications needed.
#2 Move your single template into the main php file
You can copy your template part to main file and replace
get_template_part(..)
with its content. Not a good idea as you will have to do this in all of the main files that use this template. It will be harder to modify them in the future.
#3 Awful but working(?)
// might not work, as I haven't been using globals for ages. I strongly advise you against that method, it's FYI here
Just do the following in your main php file:
//before starting the while loop
$divId = 0;
And in your file with template at the same beginning:
global $divId;
Then, just replace following:
id="box"
with
id="box<?php echo ++$divId; ?>"