You don’t need any plugins to accomplish this. In fact, this is not really a use case for a masonry layout since the heights of the images are all the same. Masonry.js is for varying post heights. You just need a counter to keep track of alternating rows, and each alternating row put the small column first instead of second. Set a counter to 0 like so:
$i = 0;
Then after each post increment it by one like so:
$i++;
Then you need to use mod to check if it’s evenly divisible by 2 (alternate row) or not. If it is, put the small column first instead of second. Check like this:
if($i % 2 == 0) {
//...this is an alternate row...
//...put your markup here...
} else {
//...this is a regular row...
//...put your markup here...
}
From the looks of your markup, you might need to modify it so it’s all within one loop in order for this to work.
Related Posts:
- Guidance with The Loop for CMS
- How can I loop into two different DIVS without repeating the DIVs
- WordPress loop specific thumbnail size
- custom shortcode will not display the wrapped content
- Multiple WordPress Menus that will only display all pages
- Syntax error when I try to insert my loop into an unordered list? [closed]
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Why in my theme I can’t see all the statics content under the posts?
- Get all posts as an array ID => Name
- home.php show blog posts as grid view
- Posts are not looping through correctly
- Why in this WordPress theme I can’t see the Main Menu?
- Search.php gets metadata from first post
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- WordPress navigation wont appear with wp_head
- How to Create Carousel Indicators in PHP Loop using wp_get_attachment_url function?
- Check if current post in loop is last on current page
- Looping through dummy posts and showing them in the main index.php
- PHP code printed into CSS classes
- Retrieving specific images from Media Library
- WP Knowledge Base Theme bug – Subcategories and Articles, Need to change WP_Query
- How to display thumbnail if post is assigned one otherwise not
- Trying to display ads on only a third of posts in a loop. Keep getting Error 500?
- Pagination not working properly
- $_html is empty when var dumped
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- Custom theme on multisite has issues with standard loop output
- Custom theme: Alternatives to long list of ‘include’ in functions.php
- Theme Options Page – User Updates Logo
- Changing layout with wp_customise
- Converting HTML Template to WordPress Theme
- How to use my style.css file outside of wordpress subdomain?
- How to show part of the_content?
- Dynamic Stylesheet loads but doesn’t finish
- Wp-login appears White Screen, Error: Cannot modify header information
- Filter Select results based on selection
- How to remove the cufon script from Dzonia Lite theme [closed]
- get_the_tags() not iterating through for/while loop, but will with foreach
- Using loop pagination on single.php
- Loop with slider (slider not loading)
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Hide categories that are not used in the post type
- How do I add custom bulk actions to multiple custom post types?
- Add_action not working in required file of functions.php
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- what is the best practice to add new field to an api route
- Grab posts by multiple categories
- Can’t access variable outside for loop
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- add custom link to wordpress media gallery modal
- Need Help Fixing My Iframes [closed]
- Iterate through posts based on array of categories
- Avoid parallax images hardcoding
- Improve page speed loading using CDN and async or defer attribute
- get author_name from queried post
- Displaying Woocommerce Product Category in WordPress
- populate form fields in a loop with ajax
- How can I add extra word in permalink when someone click download button?
- Error in custom php function doesn’t exist
- Customizer: active_callback and sanitize_callback incompatibility?
- post created but no permalink
- Increase offset while looping
- Blog posts repeat
- How to add condition in wordpress loop? [closed]
- Woocommerce : Can’t get product info in loop
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- Populate editor with some content of a page with a page template
- Two queries for a WP_User_Query search work perfectly apart, but not together
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
- Alert Bar section within WP loop is displaying even though there are no posts
- Menu jumping when calling it via PHP
- remove post that has no content
- Display category name only once inside loop
- WordPress Multiple Navigation bars
- Displaying recent posts on static page with template-part via shortcode
- How to edit widget code to add unique class name to each div?
- Can’t find infinite loop cause
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Skt full width basic slideshow problem
- Load wordpress content in other domain
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Checkbox doesn’t stay checked, conten
- Using Select HTML in Bootstrap Popovers
- How to disable controls in theme customizer?
- How do I link a button I created in theme customizer to a function?
- Trying to retrieve post meta
- can i fetch a custom metabox data in another page or post type?
- Add class to group inner container
- Is there a way to conditionally check whether a WordPress post title is empty?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- get_template_part for specific page
- WordPress style.css not updating, only after theme reload