Give this a try?
function oddeven_post_class ( $classes ) {
global $current_class;
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
return $classes;
}
add_filter ( 'post_class' , 'oddeven_post_class' );
global $current_class;
$current_class="odd";
and be sure you’re using <?php post_class(); ?>
Related Posts:
- Get current post id in functions.php
- adding a custom css class to post
- How to add padding between posts
- Custom colors for post rows based on post meta value
- Limit function to specific post category
- Hiding posts in a list from specified categories
- Add a class to post title if a link ends with a certain extension
- How to make classes for posts?
- Change post order random through out the entire WordPress
- How to do set post permalinks using 6 digit random unique function?
- Redirect to another page using contact form 7? [closed]
- How to check in functions.php if there is data in a WP_Query?
- Related Posts function not working
- How can I add a class to particular paragraphs in my post?
- Query function not executed between element [closed]
- Same post appears in related Posts?
- how to show comments only author which send own posts in wordpress
- Function is printing twice – any suggestions?
- Show all posts from the tags without having to set all of them
- Filters do not work when there are multiple (one works)
- How to change the case of all post titles to “Title Case”
- Adding additional data to WP_Post object
- WP_Query: Why is sticky post not first item in loop?
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- Code to auto expire posts after 30 days
- This AJAX Code Doesn’t Work – Looking for elegant solution
- Custom wp_trim_words() function not trimming right
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Delete Post From Front-End and attachment permanently
- Hide Post comments when displayed via WP_Query
- Function to show random posts from a category
- wp query with dynamic taxonomies and terms?
- Blogroll – Different layout for first post
- WordPress Theory Lesson – Image Columns within posts with alignment?
- How do I use `posts_distinct` correctly?
- Automatic value for custom fields for posts
- Loop through all product posts?
- How to find what index page a post is on?
- Uppercase first sentence in every post
- Get Posts that are in the current month or later
- WP Query to Get Array of Slugs
- How can I sort posts by the date and a custom meta field?
- Hiding Draft Post In Admin
- How to verify wp user password by sql query in wp? [closed]
- Force the “Choose from the most used tags” meta box section to always be expanded
- Making a custom Pagination for multi page blog post
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- WordPress query_posts by tag doesn’t work anymore(?)
- Ignore latest two posts
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- Post type no single page
- Adding a user’s ID behind the tag ref link address
- Why posts array is empty?
- How can I insert a new markup element after 4 posts automatically? [closed]
- how to handle the loop using filling bootstrap grid structure?
- Microformats in a single post – layout conflict
- How to display WP Query filters?
- Finding a post’s slug
- Is there a function to get post info for any publish_status by post ID?
- How Can I Always Display A Particular Post First Using WP_Query?
- Optimal WP Web App Backend for mobile app development
- Different background colors for posts with WordPress
- How do I display main query posts in random order using add_filter
- How to put the author of the post in the comments?
- Check if almost 10 year old – working code is up to date
- How to add a custom class attribute into code wrapper? [duplicate]
- query posts with selected post ids first
- Remove pagination if search returns empty
- Remove HTML tags from all posts
- Order posts inside bootstrap card columns
- Save All Post Permalink From A Specific Category into a .txt file
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- Counting Posts by Category
- show image gallery in archives or category page
- Page with Category Returning 1
- Displaying POST content with HTML tags and all
- How to Display Most View Post in the template file?
- wp_query args with relation
- Get 5 most recent categories
- Show post excerpt
- How do I apply a wordpress function to something with no ID inside an archive page?
- Show author bio box
- Creating Ordered Query using Meta_key
- Call image from post on index page?
- WP Query between posts custom fields [duplicate]
- How do I get thumbnails?
- Retrieve latest post by multiple categories with ID
- Update Post with Modified Data
- How to Include a common category in a custom Category Search
- wp_query select if have comments
- Notify Author of the post if admin deletes his post and perform some function
- wp_query posts sorting doesn’t work
- Trying to create shortcode listing custom posts, but formating not being included
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Get posts after calculating meta key
- Difficulty hiding a span per a body class within WordPress