It’s a little bit hard to guess, what exactly do you want to achieve (you’ve mentioned something about four posts in a row and then there is number 6 in your for loop), but…
If you want to display only 4 posts in your loop, then you can use current_post
field of $wp_query
, so the loop may look like this:
<?php while ( have_posts() and $wp_query->current_post < 4) : the_post(); ?>
<div id="home_post_<?php echo $wp_query->current_post ?>">
<?php get_template_part('template-parts/content', 'home'); ?>
</div>
<?php endwhile; ?>
// you don't do anything if there are no posts, so there's no point in checking if (have_posts())
Another thing worth to remember is that if you’d like to show only 4 posts on your home, then it’s a good idea to modify query accordingly – so it doesn’t get redundant posts.
Related Posts:
- Why in my theme I can’t see all the statics content under the posts?
- WP Knowledge Base Theme bug – Subcategories and Articles, Need to change WP_Query
- Is having multiple theme customizers for different pages possible?
- How to export/import theme customizer settings?
- reason of splitting theme files to multiple files
- How to get the registered sidebar’s name by its id?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- One button to change all settings in theme customizer?
- Guidance with The Loop for CMS
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Design view breaking on Pages
- How can I loop into two different DIVS without repeating the DIVs
- Use different javascript files for each page on website
- WordPress loop specific thumbnail size
- How to get custom image size for image uploaded in Customizer
- Passing array in add_option()
- Widgets not showing in my custom theme
- How do themes render caption texts in extended markup (e.g. “wp-caption” paragraphs)
- Changing the template hierarchy
- Can’t load WP function into external function
- Set WordPress Default Template
- Customizer: Output default value in Customizer CSS
- WordPress does not load page.php, return 404.php
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- Customizer: active_callback and sanitize_callback incompatibility?
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- How do I link a button I created in theme customizer to a function?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- What does this mean in wordpress? Easy question
- Syntax error when I try to insert my loop into an unordered list? [closed]
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Reason to add a name of the theme like (‘menu-1’ => __( ‘Primary’, ‘twentynineteen’ ),) in PHP?
- Separation of presentation and code – WordPress
- WordPress Customizer Default Image
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- get_template_directory adding FTP root folders in urls
- How to add the sidebar to all the pages except the home page? [closed]
- Header not properly displaying on archive.php
- Save Custom CSS file in the upload folder dynamically?
- Warning: printf(): Too few arguments in helpers.php file
- Get all posts as an array ID => Name
- How to Update an old theme for the latest wordpress version
- get_comments_number() returns 0
- How to correctly load a different version of main menu based on the user language in WordPress? Is it a good solution?
- Why in this WordPress theme I can’t see the Main Menu?
- How can I assign separate stylesheets to different pages?
- How to make sure relative URL works when site is not on root domain?
- Search.php gets metadata from first post
- Commas in Tag Cloud
- WordPress redirects page query parameter in URL
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Not able to remove caption shortcode from the content
- When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php
- Check if current post in loop is last on current page
- Unable to retrieve get_author_posts_url
- Display post date also if the date it’s the same for each post
- Looping through dummy posts and showing them in the main index.php
- WordPress child theme, creating a custom php template page
- Menu to the right of screen on desktop using Bootstrap 4
- How to add Open/Close Toggle button into Twenty Fifteen theme for hiding left sidebar?
- Problems with the WordPress loop [closed]
- Use Custiomizer to setup meta theme color tag
- Rotating Header Images
- Create a custom theme-specific page, invisible in the admin-panel?
- Image not displayed
- Inserting A Feed and Sidebar into an HTML Page
- Trying to display ads on only a third of posts in a loop. Keep getting Error 500?
- Predefine Magazine Style Layouts
- Pagination not working properly
- $_html is empty when var dumped
- How to store the_post_thumbnail() value in a variable
- Font Awesome Icons as squares [closed]
- PHP unit testing WordPress?
- Grab the first paragraph of each post
- Replacing mysql_real_escape_string in WordPress theme
- Woocommerce, recognize the loop of related products
- Easiest way to show total number of subpages
- Output 2 items within the Loop
- How can I add pagination and how can I change thumbnail size?
- How can i upload images in an admin page?
- WordPress: Access a plugin from within a theme
- How to change theme programmatically from a external application?
- PHP Warning: strip_tags() expects parameter 1 to be string?
- Only show first image in foreach loop
- WP_Query multiple post results
- Convert Featured products loop into Recent products loop?
- Toolbar Hidden in a Virtual Page
- Wp Query : Order by distance lat,lon
- Remove Custom Post Category In WordPress Slug Using .Htaccess
- How to set all External Domain Links with nofollow Attribute from Header Footer Content and Excerpt using PHP?
- How to Add a cutsom slug to my custom author role
- How to output the taxonomies that are assigned to each custom post?
- Force Sidebar on Full Width page
- How to count posts posts if they are in a separate content page?
- Custom Taxonomy Link Text Echo Name Not Slug
- Implement “No related posts for this entry” into the loop?
- ACF | WooCommerce | Theme Development | How to include a /template-part/ that makes use of ACF’s on a custom WooCommerce homepage?
- Twig+WordPress how to use array arguments inside a function?
- WordPress PHP8 Critical Error in class-wp-widget.php