$i = 0;
while (have_posts())
{
$i++;
the_post();
// Output the post
the_title();
the_content();
// Output an ad after each third post
if ($i % 3 === 0)
{
echo 'ad';
}
}
The %
is called the modulus operator.
Related Posts:
- Difference between an archive and a page listing posts
- Automatically create a new page daily with last three posts
- Connection lost. Saving has been disabled… (Updating Posts/Pages)
- Clear cache when a post is submitted [closed]
- how to limit edit_form_after_title hook to page and post edit only?
- Strategy for handling hierarchical pages with empty parent content
- How to add a new tab to page editor
- How to change post to page
- Create custom page in WooCommerce
- widget should display post archive by year and on click also by month
- Determining Slug Before and After Edit
- Static posts page with home.php
- Change WordPress post-state in Admin Area
- Single.php Active Category Class
- how to show all post in my page-grid.php template page
- eBooks download website, page or post?
- Link for the page archive for posts, like using custom post types with get_post_type_archive_link
- Can I hide a specific post from latest posts page?
- How to get the latest posting time of archived pages in WordPress?
- Hide add new page button
- How to show post(excerpt) from specific category on wp page?
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- How to restore permanently trash page? [closed]
- Creating a Page of Posts
- Category List (Archive) Page Template By Category
- post-page: reference to parent page?
- Dashboard :10 Last draft page and 10 last pending review page (metabox)
- How to display data in archive page?
- page.php showing loop of posts and not page content
- Can I divide the pages into categories?
- How do I get blog posts to appear within CMS?
- Drag posts and pages so you can sort them in order
- How to include the latest post of a specific category on a matching page
- post categories
- Archiving by academic year instead of calendar year
- What’s the best way to render Visual Composer in posts, not pages?
- Start post pagination at 0 instead of 1
- Is there a way to specify an extra class for a post or page with no title?
- Using wp_list_pages() after calling query_posts()
- Multiple Loops Breaking Pages
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- disable Tab post on nav-menus page (Admin)
- Proper way of establishing custom landing pages in WordPress
- Admin – no Featured image choice in create new/page|post
- Why won’t pagination work?
- How to add some html formated text to every new post in WordPress
- Output Post with ACF Fields into other Post
- Posts and Pages: 404 Page not found
- List all posts, pages and custom post types in admin
- Make ‘blog’ page show content as well as posts underneath it
- Are post, page and category IDs unique to each other?
- Display in category ( taxonomy) a number of post that I want
- Setting limit to posts or page creation
- Find out in which kind of archive am I
- Create a frontpage.php and static page template
- Using Posts Like a Page
- Pagination for normal (standard) posts on a page with a custom loop?
- post/page content
- WordPress Architecture as a CMS – Posts & Pages
- Is it to possible to insert a page in the post depending on the category ofthe post
- How can I add a page that shows posts from a single category?
- How to show next/prev link, when it’s not active?
- Permanently deleted posts still exist
- Automatic duplicate/copy of post to a related page in WordPress
- Yoast breadcrumb URL shows category instead of the page
- How to hide protected posts from archive?
- Nestling Posts Under Page & Justify Text
- Redirect to custom post if custom archive page has just one result?
- Added a ACF field to custom page and want the results to show as a column in admin
- Deleted page still shows and is showing posts archive
- Disable pagination in posts and pages
- WordPress for business site
- How do I make it so that new posts within a certain category go into a certain page?
- Page 2 has no posts?
- Any difference betweenn posts and pages for one page?
- Add custom class to existing menu items from custom meta
- Bulk replacing content of multiple pages/posts?
- Allow users to create their own page/s
- how to change the permalink to a specific location?
- some posts being displayed as pages
- One of my posts is displayed as page
- Make Show Notes for Individual Podcast Episodes Easy to Find (multiple URL’s?)
- Get part of a page url
- can’t post immediately
- Displaying only posts from a certain category on my custom page template
- I need to create a page or post hierarchy
- Home page: using custom fields for posts and pages
- Where are my posts linked to? I keep getting a Not Found Error, and I have no single.php page
- Automatically delete default posts and pages on theme install?
- How do I add an article to specific page?
- How to get pagination working with “Pending” Posts
- Custom post page has attributes of latest post [closed]
- WordPress “Posts Page” isn’t showing template dropdown
- Adding Count Post in Page
- Insert Shortcode exactly at the end of the content
- How to have 2 posting pages on a blog
- change page name on page list
- Display post count on archive page in reverse order
- Filter/Sort Post Form On Taxonomy page
- Edit Page button is gone