You need to make two changes in your code
- Use
$i = 1
instead of$i = 0
(before begining of while loop) - You have 2
IF
condition in which you using % symbol. You need to make changes in first if condition (only in opening ul tag).
Just replace
if($i % 4 == 0) {
with this
if($i % 4 == 1) {
NOTE: Don’t make this change in your second IF
condition (codition with closing UL tag i.e. ).
To check what’s the difference between previous output and this one, just print value of variable i ($i) near title of post and your will notice why this changes required and how it actually solved the problem.
Related Posts:
- My Custom Post Type AJAX Query is Returning no posts – why?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Post form – AJAX won’t upload featured image – Plugin development
- How to Send Pingbacks for all Posts in WordPress?
- How to display 8 posts in four columns and 2 rows on a carousel slide?
- Display articles with a different template in the home page | Solved |
- How can I check if a post with a particular slug or title exists?
- WordPress sorting posts by date and title using a dropdown
- How to get post image caption by index
- posts_per_page displays only 2 posts instead of 4 posts
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Is there anyway I can call the year once?
- Query on a repeater date (acf)
- Time Stamp In A WordPress Post Title That Does Not Keep Refreshing
- How to get post titles by post ID and integrate with my code?
- Check $post->ID against multiple values
- Trying to get post ID outside loop on blog page
- Don’t update modified post date when user add a product review or comment?
- Limit the number of characters/words in an excerpt for a related posts section
- Posts missing on author page
- How to allow users to save list of posts in wordpress?
- Infinite looping next post link within a certain category on a post
- Trying to show the category of a post in the post display
- Split post or page content in two or more columns
- Enqueue script only on child pages of custom post types
- Attach and retrive multiple pdf files to post or page
- WordPress recent post
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Show a text if the post has written by author user role in WordPress
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- Send POST request to Flask app from functions.php file
- Getting info about selected posts using one WP_Query
- Closing Comments conditionally in comments.php
- Change upload URL by mime type
- How to center all text body in single.php at once?
- Get list of posts from attachment
- How to pull date/time in french format for wordpress post?
- Send Notification after post published was working but stopped after the last WP update
- How to use a PHP file to control the content of a blog post
- Having trouble with customizing blog posts on the home page
- Related Posts: if there is no category use tags
- My blog posts section seems to be rendering the other blog posts inside the first? :/
- WordPress post insertion from PHP file
- LinkedIn Share Post Button
- How to display last whole post on the homepage
- How do if all posts has this category ID then do this
- How to insert text into post based on category – via single.php file
- When working with a post, almost all wp_postmeta are deleted
- Make sticky post with FacetWP
- WordPress Single Post Pagination Numbered and Navigational
- Getting page / post URL on publish and / or update
- Let user select the number of posts shown per page jquery error
- Get the total Author Favorited posts
- Add wp posts to cutom masonry grid
- Displaying POST content with HTML tags and all
- Generate random access token to a post page
- Get current_post in reverse order with pagination
- Getting error in sql query
- Displaying 3 Category Posts differently
- Pagination in WP Queries
- How do I generate formatted permalinks as specified in backend options?
- Using Tag Groups: Displaying groups and adjacent tags of current post
- Setting at job with shortcode not working
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Add div after every 4 posts then every 2 posts for a responsive loop
- Only display notification on single post
- Insert div after every three posts in home.php [duplicate]
- PHP tag in post content makes wordpress go crazy
- Unable to get Post Category Name and URL
- Display 6 most recent post on homepage?
- Dynamically Create Posts Via XML File
- Basic PHP question (displaying post title over thumbnail) [closed]
- Only Get A Certain Number of Posts From WP_Query
- Apply filters when loading post via ajax
- Get posts associated with media attachment
- insert thumbnail image from php script
- ‘posts_per_page’ in costum page type
- Disable single posts, but keep archive
- Add multiple HTML attributes to an Elementor button
- WooCommerce: write featured image dimensions to custom fields in product’
- How to create a WordPress PAGE in another folder?
- How do I get a function to work in single.php
- transition_post_status hook, works – but not if the post is new
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- Bulk data save in custom table
- How to change post date and post time in WordPress automatically with a function
- How to get ACF field to show up on all posts on front end?
- Global update of records after import WP All Import Pro
- Display posts based on the selected category when no subcategory is chosen
- Display two previous posts on single.php
- (plesk)After adding 1000 youtube url to my 1000 different wordpress article, my all websites doesnt show yt url as embed
- change the blog in the url if you go from a specific page wordpress
- How to make posts_like_dislike reference current post when iterating?
- Category Attachment Pagination 404 Error on 2nd Page
- Warning: Undefined variable $post_id
- Issues applying JSON body filters in EU F&T Portal SEARCH API with WordPress integration
- How to display only the first 2 words of a post title