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
- WordPress Themes and PHP unit
- Remove Customize Background and Header from Appearance admin menu without CSS or JS
- Dynamically change feature image in customiser
- Display only text to WordPress loop without loosing the text formatting
- Design view breaking on Pages
- get understrap pagination to work with custom query
- Is it possible to use the featured image of a page as a css background without inlining?
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- How do I translate this string – PHP syntax question
- Site Health : An active PHP session was detected
- Way to display “Yesterday”, “Today”
- using add_action for a header hook that has an additional parameter
- multiple if statements [closed]
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- Using a `Template Parts` folder instead of an `Includes` folder in a Custom WordPress Theme
- Set the checkbox as checked by default at options page
- How to set variable, pass it to a partial file and remove it after?
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Can’t find infinite loop cause
- How to disable controls in theme customizer?
- What does this mean in wordpress? Easy question
- WP_Query fails despite having 1 post
- Loop stopped working
- How to loop through all the attached images in a post, and get their url one by one
- Show About and Contact Us page when they’re clicked in the top menu.
- Is There A Way To Make Theme Files Accept Shortcodes?
- Store post content in a php variable and output them using for loop
- Need to add class to first element in a foreach loop
- WordPress import media error
- Show recent posts starting at a specific number archive
- Hide Heading if ACF Field is empty
- How to get the last category name of a child category?
- WordPress query undefined offset in loop
- Issue with custom loop in Archive page
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Getting posts to exclude from array
- WP Query Leads to 502 Bad Gateway (Timeout Because Query Takes Too Long)
- Custom post type permalinks do not appear using the link functions
- Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?
- Using bloginfo and divs inside a php file
- WordPress call post-ID in jquery
- How to organize functions.php content
- How to extract information from a wp_query result?
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Search page results conflicting logic – Search result caching?
- List all anchor links on a page
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- How to extend SelectControl with data from my theme
- excep tonly one css, don’t load any css
- How to use wp_get_attachment_image or wp_get_attachment_image_src instead of $instance[‘single_feature_image_uri’]
- update_user_meta as multiple value but with same meta key
- Responsive loop with 3 columns inside row then 2 columns
- add custom link to gallery images
- How to bind each “the_content” elements to a custom variables
- Posts in two different columns Bootstrap
- How to properly escape in ternary operators – Wp Coding Standards?
- Date of last blog update for specific authors only?
- PHP for loop not working as intended
- How can I customize a WordPress theme before it’s downloaded?
- Insert div after every three posts in home.php [duplicate]
- Display product attributes for current product
- Trying send mail from Theme page
- How to have post count after each listed category
- How can I put a custom field as the link of a button shortcode?
- Transient Loop Not working as expected
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Shortcode working in page.php but not in category.php in wordpress
- Adding a Sub Menu Options Page WP Backend Menu. Whats wrong with my code?
- Conditional in foreach loop is outputting content twice
- is there away to hide php code in wordpress not to show in PAGES
- How can a ‘scripts’ directory be hooked into wp_head();?
- WP and Laravel integration (Updated) [closed]
- Woocommerce Convert existing order to the cart