It just take a little bit more complicated logic:
function alternating_post_class($classes) {
static $counter = 1;
switch ($counter) {
case 1:
$classes[] = 'full-width';
break;
case 2:
case 3;
$classes[] = 'half-width';
break;
}
$counter = ($counter == 3) ? 1 : $counter + 1;
return $classes;
}
add_filter('post_class', 'alternating_post_class');
Related Posts:
- Theme Check: Could not find post_class
- The the_post_thumbnail without srcset?
- after_setup_theme always runs
- WordPress API Menu/Submenu Order
- How to move page template files like page-{slug}.php to a sub-directory?
- What WP folder can I use to write files to?
- Are the WordPress Core CSS styles really all nessesary?
- Why I can’t add a CSS style in this WordPress theme?
- How to make a theme with more than one CSS file?
- register_sidebar ignores ‘id’ and ‘class’
- Display a different theme for not logged-in users
- Best practice (forward compatibility) for theme options
- Add colors to existing color palette without replacing it
- Single Page WordPress Theme – Using page templates
- Select menu on browser resize
- Can I upload WordPress-react theme in Wp theme repository
- Returning Variables back into a template
- new theme permissions don’t allow me to edit
- Which theme foundry has clean coded themes, where code is poetry [closed]
- What page should I use for a contact form?
- Retrieve data using wpdb to use for customizer controls
- How can a Theme Contain no Header File or Footer File?
- Cannot get full thumbnail size using the_post_thumbnail
- Is there a way to activate different theme for specified users? [closed]
- Some translations do not work in my template class
- WordPress not registering Theme Customization Section
- How to remove a file included in parent theme with locate_template() via child theme?
- How can I display/hide certain content based on a Theme Option field?
- How can I make that when I clic on one of the menu items, that page shows only posts with the same category?
- How to add infinite scroll?
- get_option in header.php not returning value from customizer
- Internal error 500 accessing Theme > Customize
- How to add “Template” option in page attributes panel?
- Theme Development: Starter Content after hook
- Change locale by detecting viewer’s browser language setting and let them choose prefered language after
- Why is it needed to enqueue parent stylesheet in child theme?
- Folder name for a pro version of a WordPress.org theme?
- Is there any WordPress theme for Self Storagae just like Spacer [closed]
- Customizer: save setting/control content to post/page
- WordPress Unite Theme: Footer isn’t sticking [closed]
- Is accessing theme and using customizer GPL distribution?
- How to enqueue javascript for WP Customize options sidebar?
- WordPress 500 Internal server error when activating custom theme [closed]
- Customize how a WordPress theme looks like in the Theme Selector
- How to set a page as homepage in stead of the newspages?
- Widget Option is Missing
- WordPress Theme Validator?
- If you were to start using a WordPress framework today, which one would you use? [closed]
- Template for landing pages
- Is it possible to have a theme that uses only one single page?
- underscores use of the article element on the page template
- Plugin does not work in custom theme
- Create a child theme from multiple themes
- html5-reset theme does not show the image [closed]
- Adding a gallery to my first theme
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- What exactly is “wordpress theming”? [closed]
- I have WordPress setup on primary domain, how do I set it up on its subdomain using the same database?
- Valid SQL query not returning results
- How do I include a partial from a directory below a wordpress theme directory?
- Change Image Sizes for Mobile Theme
- Recommended sidebar / content widths
- Converting a theme to a child theme in a network
- showing all recent posts in theme
- What is the difference between Twenty eleven & roots framework?
- List categories of a post hierarchically?
- Is there a list of default generated Gutenberg block CSS? Unable to align video blocks
- How to change listing type permlink?
- Adding popup support to the theme
- Calling a WP Plugin Function’s Variable in Theme Template [duplicate]
- How to make updatable custom WordPress theme?
- How can I access variables from theme in child theme? [closed]
- Local variable name in setup_postdata()
- Creating a Single Page Theme correctly
- Is it possible to echo a woocommerce prouct attribute discription?
- Child theme menu not appearing in Twenty Seventeen
- How do I remove header/page-title image in farvis theme? [closed]
- How to link post image to post link?
- WooCommerce – edit templates
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- How to dowload and edit content of a website
- On wordpress, how do i require specific dimensions from user uploads only
- WordPress Theme Developments – Start from another theme
- Slider should be display in home template [closed]
- Modify comments_popup_link output
- Best strategy for providing theme options using customizer
- Next post in category
- Can you create a custom page with content in the center already defined?
- How to migrate the menu from the site on my own theme in WordPress?
- RSS feed url showing page not found. How to solve it?
- How to convert that page to a wordpress template? [closed]
- Toolbox theme using printif statement – help needed understanding code block
- php file child theme directory not overriding parent theme php file [duplicate]
- Any Cool WordPress Theme Editor? [closed]
- How to Create a Multi Purpose Theme?
- Custom Single Page Portfolio Theme [closed]
- Is there any open source WordPress Themes?
- How to make a multilingual wordpress site to be translated one-to-one without much effort and without using translate?
- Is there a way to have WordPress autodetect page templates in the page-templates directory and any sub-folders?
- My wordpress site memory exhausted more than 1GB trying to debug with default