Add class to 1, 3, 4, 6, 8, 9, 11, 12, 14 etc

I want to be able to add a class to div in that particular order above.



Only the divs outside should have a specified classes. This is basically from a WordPress loop:

<?php

    $args = array(
        'post_type' => 'resources',
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'ASC'
    );

    query_posts($args);

?>

<?php if ( have_posts() ) : ?>

    <div class="resources">

        <?php while ( have_posts() ) : the_post(); ?>

            <div class="thirds">

                <?php the_title(); ?>

            </div>

        <?php endwhile; ?>

    </div>

<?php endif; ?>

so i see you have a numbered range of integers from X to Y (e.g. post-positions or post-ids), and you know how the alogrithm works. and you may have some experience in the particular programming language. my conclusion is: you have everything to build a test on your own, and then apply the function on your live dataset.

This is what I ended up doing:

<?php

    $args = array(
        'post_type' => 'resources',
        'posts_per_page' => -1,
        'orderby' => 'date',
        'order' => 'ASC'
    );

    query_posts($args);

?>

<?php if ( have_posts() ) : ?>

    <div class="resources">

        <?php $counter = 0;     // started a counter ?>

        <?php while ( have_posts() ) : the_post(); ?>

            <?php $counter++; ?>

            <div class="thirds sequence-<?php echo $counter; ?>">

                <?php the_title(); ?>

            </div>

            <?php
                // check some shit...
                if( $counter == 3 ) {
                    $counter = 0;
                }
            ?>

        <?php endwhile; ?>

    </div>

<?php endif; ?>

And then I use sequence-1, sequence-3 to add the custom styling.

how does your counter comply with the Beatty Sequence?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.