If you can update your theme files, just update category.php and archive.php this way:
<?php
$counter = 0;
while ($the_query->have_posts()) :
$the_query->the_post();
?>
<?php if ($counter % 4 == 0) : ?>
<div class="my-ad">my ad</div>
<?php endif; ?>
<div class="post">
<?php the_title(); ?>
</div>
<?php
$counter++;
endwhile;
You can also change archive/category template by your own via plugin with template_include
hook.
If you can’t access your theme, use loop_start
or loop_end
hooks:
add_action( 'loop_start', function( $query ){
if( $query->is_category() ){
}
});
Then place your ads between posts with js.
You can also hook to the_post
or the_content
, check if it on category/archive template and add your ads according global count variable
Related Posts:
- Woocommerce product not appearing in category list page when created programatically [closed]
- Creating an archive page listing external data
- add_action hook for completely new post?
- How can i list current author’s categories?
- How to Make a Category Always Selected?
- anything like add_meta_box for categories?
- Calling clean_term_cache() fails when called in the same plugin that creates terms, succeeds when called separately?
- Missing “category_children” option when dynamically creating categories via a plugin
- Can we create a category list page in WordPress?
- prevent post to have multiple categories in my plugin
- Show add_meta_box by selecting a specific category
- Which are the hooks run before/after when a category’s deletion?
- how do you prevent showing a particular category on the admin dashboard for specific user roles?
- Is it possible to change a term slug before being saved to the database?
- wp_insert_category() setting the ‘cat_ID’ gives not array error
- Send push when new post is published in a certain category
- How do I get the sub categories of the parent when in a sub category?
- Filter Categories widget to allow custom sorting?
- Function/Class to list categories with checkboxes
- How can I show posts for a single category?
- Check if post belongs to any category
- How to display the categories on page using shortcode?
- How to display the category id along with category name on categories list?
- add_action pre_term_description vs. pre_category_description
- How to show parents of current page category, excluding the category?
- WP Dropdown Categories, display subcategories but not grandchildren categories?
- Load stylesheet in edit category page?
- How to relate the Category to user?
- How to exclude categories from get_categories() select list inside a widget admin panel
- How to Show Category List With Corresponding Links?
- Exclude Woocommerce Product Category From Sitemap
- How to create archive page to add in menu
- How to overwrite the category template in a plugin
- How to show only the last two categories in a menu?
- Determine if term is Category or Tag
- How to check category name available or not
- delete category on plugin deactivation wordpress
- Post is uncatagorized in publish_post action
- Overriding the template files using a plugin for all themes
- Hide post by ‘post_category’
- Yoast and another plugin
- Making Woocommerce optimized for more than 500k products
- Add a new tag based on the category name in the publish event
- How to display archive by selecting year and then selecting month
- How can i call from custom fields to the category editor?
- filter on get_posts efficiently
- How to get recent one post from each category on home page?
- How can I set up the URL for a category archive for a custom post type?
- Error on using __FILE__ for add_menu_page() Function
- Updating Style From WP Options Setting Page
- Getting error of unexpected output during activation
- Use custom clean URLs for a plug in
- Cannot echo a JS variable to a jQuery plugin coming from wp_localize_script
- admin page passing $_POST variables to itself
- Adding parent custom post type menu option
- Categories in custom post types
- How to show custom taxonomy child posts through shortcode in WordPress
- Ajax url value to pass ‘variable’ to use in query
- Can wp_schedule_single_event be used to run background proccess?
- 2 loops in archive.php (one for each category)
- Archives and category of authors
- Is it possible to make WordPress as a RESTful app?
- Change Admin menu placement using hooks
- List all content by post type
- Ajax functions – no access to wp-admin.php only online
- Best Way to Grab Post ID from Plugin
- Adding querystring variable breaks admin URLs
- How to check during “pre_get_posts” if WP performing default query for specific custom template?
- Search tag within category
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- Client Profiles
- dynamically filter by category via sub-menu
- Changing upload directory for plugin uploads only
- dbDelta not doing what it says
- Fetch the input type date value via ajax
- Multi-part form and wp_redirect()
- Add Page With Parent ID
- Yet another wp_insert_post infinite loop. What is wrong?
- Data Validation, dynamically generated fields (select for example)
- Initialize class inside plugin
- Thumbnails for media Library images
- How can I add the custom taxonomy categories to the posts and pages?
- How to Rewrite WordPress URL for a Plugin
- Add query string variables to all hyperlinks URL matching a specified domain
- Stop header code from showing in category page?
- WordPress multiple user roles accessing on their information on one site?
- loop and in admin header problem
- How do I replace title with my plugin?
- Remove image in post when it’s removed in media library
- Virtual Page with Registration form
- add short code not working
- Practical Solutions to HTML5 Video on WordPress
- An adiitional function fires on my AJAX submit
- Plugin options page – save two related options as one entry
- Create and style menu
- Create pages for authors
- Projectmanager Internal Link Code Location
- How do I create Widget within plugin that uses its own class?
- Select options not reloading after form submit
- Get URL of Post You Are Editing