You need to create a variable with the count and then check against it e.g.
$num = 1;
foreach ( $terms as $term ) {
if($num%2) {
echo '<div class="something">';
}
// other stuff
if($num %2) {
echo '</div>';
}
$num++
}
The %2 is the part you need, it checks whether the number is dividable by 2
Related Posts:
- Endless loop with wp_insert_post and wp_update_post
- Add Incrementing ID to each paragraph in the_content
- post__in – Placing content from a foreach loop inside of an array
- In a foreach loop, how do I target the last item in the loop?
- How to iterate through database until it find a match
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- How to print out menu names in the foreach loop?
- Add class to last 3 posts in loop
- Output meta into arrays
- Need to add class to first element in a foreach loop
- Foreach displays from last to first
- Simple foreach loop help needed in wordpress “the loop”
- How to print redux gallery feilds id? [closed]
- How to check all items in a loop have post thumbnail?
- Get featured image outside the loop using foreach
- Why loop renders only last metabox from array? [closed]
- Foundation modal in wordpress php loop
- ACF field not appearing correctly in loop
- Eliminate duplicates in a foreach loop [closed]
- ACF loops false value with repeater and checkbox
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- How to get Author ID outside the loop
- remove tags from the_content
- the_title() shows title of the first post instead of the page title?
- Why do themes rely on “The Loop”?
- Two custom loops, pagination, offset
- What exactly defines a Main Loop and a Secondary Loop?
- Loop code is displaying pages but not actual posts
- Access to Media Library
- Getting two wp_link_pages output
- post loop causes wp_users and wp_usermeta DB queries for each users
- Looping through WP_Post Object
- Ajax loop refresh on click
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Is get_posts() more efficient than The Loop?
- loop through all posts memory error
- Targeting a Certain Post in Loop (CSS)
- Get post/page data outside the loop
- Changing layout with wp_customise
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- get author_name from queried post
- Trouble Formatting DateTime
- Order archive results by post id in custom taxonomy template
- pre_get_posts for two loops on same page
- Modify the main loop to display current month / year
- Problem with displaying HTML content after in_array [closed]
- post thumbnail, conditions, else wont work
- Get author_id in wordpress
- Single.php different behaviour from admin to non-admin
- Can’t access PHP array inside script localization from javascript
- ACF – add a group inside a repeater [closed]
- How to create bootstrap grid loop?
- Why in my theme I can’t see all the statics content under the posts?
- Get post offset/posts page offset in single post page (outside the loop)
- First article : single column; Other articles : 2 columns
- How can I access specific posts brought back by query_posts?
- get_comments with post_status ‘public’ retrieves NULL result
- Content Visibility for WordPress is not working (Drafts, public etc.)
- How to unlink all posts from tracking same amount of views
- Generating a perfect loop
- I need to display all post in onepage
- WordPress loop not working only on home page, works on all other pages
- Exclude category from get_the_category
- Video post format, extra content breaks video embed
- Strip from or something better?
- Why is my category post repeating twice
- Adding a featured image to a foreach WordPress loop
- Hook to main query with filters based on custom fields
- How can I change how my tag pages display?
- CPT loop doesn’t seem to account for post date?
- Get a Post Loop based on Logged in User information into a Shortcode
- Loop keeps showing the same post even when I click on a different one
- in_array not working on dev server but works on localhost
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- Display all the terms within a custom taxonomy
- Display page content in different sections – based on page break block?
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- Submit form for loop of products of the term with AJAX
- Customizer settings using “for” loop
- Add active class to foundation 6 tabs while looping categories
- Get current_post in reverse order with pagination
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Div Missing In Custom Loop Query
- WordPress query posts by custom post type not workng
- Repeat code, change variable?
- Using page template to fetch posts in page
- Foreach loop inside foreach loop?
- Ajax category pagination problem
- Unable to login + Redirect loop on mobile
- Variable not working in sidebar loop
- 2 loops in blog homepage
- Custom Meta Box If Else Statement
- Retrieve IDs from custom field, count and display results differently according to count
- Help with add_filter(‘the_content’, ‘some_function’) and multiple matches
- Post thats in Two Categories, only want to display name for one
- Alternative loop syntax error [closed]
- How to handle parent and child pages?
- Undefined variable: woocommerce_loop [closed]
- How to create a loop that will display one post and stop?
- Hook in the loop after the first post