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 do I add CSS options to my plugin without using inline styles?
- How do I create links at the top of WP_List_table?
- Why Does get_posts() Return an Empty Set?
- Get list of available wordpress actions
- Where to enqueue stylesheets for plugin?
- stray elements
- Deletion of shared options using uninstall.php
- Plugin Settings not Saving on Ajax re-ordered table
- I want exclude the particular category in sidebar
- WordPress password reset – why post rp_key?
- How to modify the new WordPress 4.5 link inline toolbar
- Proper way to hook wp_get_attachment_url
- How to install WordPress Popular Posts plugin twice?
- Get the link text
- Multisite plugin development and wp_enqueue_script
- Prevent plugin from deleting important directories
- Is Dreamweaver CS5 a serious choice for theme/plugin development?
- How to set “Site Address (URL)” programmatically on WP multisite?
- Reset plugins version cache | pre_set_site_transient_update_plugins
- Add column and post filter for a custom post type field on the edit.php page
- Category index featured image
- How to fetch all images from a WordPress draft using PHP?
- parse content from wikipedia article replacing search term with the title of article
- Custom archive.php: retrieve right post categories?
- Strange Situation When Try To Retrieve Github Gist Using wp_remote_get
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- WP Plugin Running before jQuery
- Prevent WordPress automatically processing certain URL queries
- insert query on a custom table using ajax with jQuery plugin Jeditable
- How to check via conditional tags for a single plugin page?
- WordPress Rest API with rest_do_request, possible race condition?
- How to disable a jQuery plugin on WordPress plugin page
- Is it possible to use WP-CLI in a plugin (or theme)?
- WP_NAV_MENU filter targets all menus
- Restore svn trunk of my plugin repository to the initial state?
- Anyone using unzip_file successfully? It uploads the zip but doesn’t extract it!
- How to use attributes in competent of Gutenberg
- Hook to execute after deleting a Custom Taxonomy
- Custom non-template page on front end fails to render
- Add custom parameter for custom user role
- WordPress Iframe for blog image
- Add the Twitter Bootstrap framework for the development of my plugins
- Code to add template to page
- Convert each new line in the textfield as a new value in an array
- Navigate to external link if last page or post in a category
- How do I control the list of Pages an author can see?
- How to work with AJAX and WordPress?
- How to count the number of monthly archive?
- Add Page With Parent ID
- Remove text from confirmation message
- Can I use an array to create multiple tables?
- Is there any other ways to replicating changes on live from staging without pushing from git
- upload image to wordpress media library failed for custom post type