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 rename “Publish” metabox title in post screen
- How to style the last post on the front page different than the others?
- Why won’t my taxonomy query show up?
- Should $found_posts be returned as string in ‘found_posts’ filter hook?
- Get random posts between specific dates / of specific age
- WP_Query get posts from custom posts by category
- Accessing post->ID outside of the loop for listing child pages
- How to find what index page a post is on?
- WP Query – duplicated posts once including tags in search results
- Limiting the number of posts in WP_Query leads to unexpected result
- Action hook for new pending posts?
- Uppercase first sentence in every post
- Add icon/badge next to posttitle of specific category
- List posts in a given category
- Ajax posts filter by date, comments, top views, top likes
- Copying and pasting emoji in a wordpress post
- Reset Popular post query?
- Yearly archive page for future year
- Prepend or add an Image to the content of a Post
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
- Query Posts multiple conditions
- Display post from current category and same tag?
- Why content_arr[‘extended’] removes paragraph tags?
- how to get posts ids inside pre_get_posts filter?
- I want to get title name of post, but i didn’t get by this code. Any suggestion?
- Get Posts that are in the current month or later
- WP Query to Get Array of Slugs
- Future post ID not showing
- How can I show many posts an author has per week?
- How do I use WP_Query to get a range of posts with custom fields that have numbers with letters in them?
- Ajax load more button in Recent posts widget
- Load post attached images on a single page site with fancybox
- WP_Query with ajax handler returns the same posts
- WP_Query orderby not working with meta_value_num and menu_order
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Custom WP_Query with complex ‘post_status’ argument
- How can I sort posts by the date and a custom meta field?
- is there a way to show the the post title after the image?
- recent posts for different categories
- Style Differently Edited Posts
- Search by post title and content in wp_query without order
- Hiding Draft Post In Admin
- Exclude category from
- How do I correctly set up a WP-Query to only show upcoming event-posts?
- Setting posts_per_page for taxonomy term template
- Blog post per page setting conflicting with custom WP_Query?
- How to insert 2 args into 1 Wp_Query for a slideshow
- How to exclude latest x posts from a paginated query?
- Setup a custom dynamic post
- Anyway to grab author name and featured image in an embeded in inital array of posts outside of loop?
- How to verify wp user password by sql query in wp? [closed]
- Removing noindex posts from wp_query
- How to display the link (title) and thumbnail post?
- WP Query – Posts Per Page not working in combination with category__in
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Force the “Choose from the most used tags” meta box section to always be expanded
- Show the content that is after the excerpt using child theme
- Ajaxify This Code
- How to allow users to post only in certain category and hide elements from edit page?
- How to filter my search in post if contains a word in title, content or excerpt?
- How to return another post than requested
- Pausing and Resuming WP_Query results
- Can’t get buddypress notifications in front-end; why do I get this error?
- Select only post id and meta value with WP_Query
- Making a custom Pagination for multi page blog post
- Lost draft under all posts and drafts
- Can I search posts and pages for css classes?
- Get user categories with most posts in it
- How do I display some posts fully on the homepage, and some as an excerpt only?
- Random ajax load only works with posts_per_page set to -1
- How to : pagination in 3 different custom loops on the same page
- Send post id through ajax and get the post content back
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Exclude the first ‘n’ number of posts of a tag from home page?
- Query posts and return XML
- how to change the number of posts returned in a specific loop without making it global?
- How to assign classes to all elements?
- Display post x of y within category
- Force authors to Preview a post before publishing
- WordPress Automatic Filename Changer