Create Infinite Looping Classes

Drop the below if statement within a loop and add a count for each colour change that you need with the template.

This is a great example to reference if you’re building a scrolling website, and loading all pages in a single progression with alternating templates applied.

<li class="training_content
<?php  ++$count;
        if($count % 5 == 1)
        {
            echo "one";
        }
	        else if($count % 5 == 2)
        {
            echo "two";
        }
	        else if($count % 5 == 3)
        {
            echo "three";
        }
	        else if($count % 5 == 4)
        {
            echo "four";
        }
	        else
        {
            echo "five";
        } ?>">
<h2><?php the_title(); ?></h2>
<h3><?php echo $subtitle; ?></h3>
<?php the_content(); ?>
</li>

Sourced here.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.