Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:43:37+00:00 2026-06-17T10:43:37+00:00

In ExpressionEngine while in their version of ‘the loop’ I can add a tag

  • 0

In ExpressionEngine while in their version of ‘the loop’ I can add a tag to any element like this:

<li class="{switch='one|two|three|four|five|six'}">

The first iteration of the li will have class one, the next is two, and the loop again after six. I’m needing this similar functionality in a wordpress site, but not sure how to accomplish that. Is there a built in wordpress function or will I need to code some sort of function in php?

Currently, using this in attempt at using @Leonard’s solution, but the class ‘four’ is being repeated over and over instead of cycling

<?php

$argsGallery = array(
    'post_type' => 'gallery',
    'orderby'       => 'menu_order',
    'order'         => 'ASC'
);
$the_query = new WP_Query( $argsGallery );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();?>

            <div class="<?php cycle('four|three|five|two|six|four'); ?> columns">
                <div class="thumb">

                    <a class="jackbox" 
                        data-group="images" 
                        data-thumbnail="<?php the_field('image'); ?>" 
                        data-title="Image One" 
                        data-description="#description_1" 
                        href="<?php the_field('image'); ?>"
                    >
                        <div class="jackbox-hover jackbox-hover-black">
                            <p><?php the_field('image_description'); ?> </p>
                        </div>
                        <img 
                            src="<?php the_field('image'); ?>" 
                            alt="responsive lightbox" 
                        />
                    </a>
                </div>
            </div>

<?php
    endwhile;
    wp_reset_query();
    wp_reset_postdata();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:43:39+00:00Added an answer on June 17, 2026 at 10:43 am

    Found this question whilst looking for the exact same thing… top of Google 20mins after you posted it. Crazy… anyway!

    I’ve come up with a function that I’ve tested (albeit quickly) that you can drop in to your functions.php and it works with a standard WordPress loop. It may need adapting for some needs but hopefully it’s a good start point.

    It uses the current_post count from the $wp_query array and works out where it needs to be in the cycle values.

    function cycle($input, $delimiter = '|', $query = false) {
    
        if($query == false):
            global $wp_query ;
            $current_post = $wp_query->current_post + 1;
        else:
            $current_post = $query->current_post + 1;
        endif;
    
    
        $switches = explode($delimiter, $input);
    
        $total_switches = count($switches) ;
        $current_set = ceil( $current_post / $total_switches)  ;
    
        $i = (($current_post - ($current_set * $total_switches)) + $total_switches) - 1 ;
    
        echo $switches[$i];
    
    }
    

    Then you can use it in a STANDARD loop like so:

     <?php cycle('first|second|third|fourth'); ?>
    

    Or you can custom delimit if needs be:

     <?php cycle('first*second*third', '*'); ?>
    

    Or if your using it with a CUSTOM wp_query you must use it like this with the query fed in as the third argument:

     <?php cycle('first|second|third', '|', $the_query); ?>
    

    I’m sure there is a tidier way to feed in that custom query, I’ll keep looking and update if/ when I find a way!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ExpressionEngine version is 1.6.8 and NOT upgradeable. I would like to set a session
I am working with MySQL in conjunction with ExpressionEngine 2.2.1. This version of ExpressionEngine
I'm receiving a MySQL Error on this code in ExpressionEngine 1.6.4 (very old version)
ExpressionEngine template code: <div class=container_16> <div class=grid_16> {if {segment_1} == home} {embed=include/title title=welcome} {if:elseif
Is this possible to do the following in ExpressionEngine: (code taken from here )
In Expression Engine the {edit_date} tag would not return a UNIX timestamp like {entry_date}
I like ExpressionEngine, but I'm starting to doubt its power. For example, I'm looking
How do we sort using the database class in expressionengine. orderby and sort are
I'm in charge of developing an extranet for a client using expressionengine. Since this
Basically I am trying to add a Pinterest feed widget to an ExpressionEngine site.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.