skip to Main Content

Is there any why to hook into wp_list_comments or something to add custom DIV with after every 5 comment in WordPress?
I know I can modify comment data or comment template but I need to get something that hook into whole comments template.

2

Answers


  1. i had done similar things in my naturopath blog. You need to find the while-loop what is getting the comments from your db. you simply add a counter in it, like we learned in first lesson of php, and add an if-clause to the while-loop.

    i = 0;
    while (your-while-loop){
      i = i+1;
      the rest of the loop
      if (i = 4){
        echo "<div>YOUR AD</div>";
        i = 0;
      }
    }
    

    It’s not perfectly well written, but i think you should get, what i mean. Comments, as well as posts are taken by while loops in wordpress. When you add a counter and if-clause to the loop, you can hook into a specific number or put something in between.

    Login or Signup to reply.
  2. Maybe you can do it with jQuery.

    First, make your div in a place that renders with your comments. You can do this modifying the template or making a plugin just for this. It is not important where in your pages it is showing, because it will be moved. Giv it a class, eg. youradd

    In a js file (you can use the same DIY plugin for this. Remember to load de js file) write something like this

    jQuery(document).ready(function(){  
        jQuery('.youradd').insertAfter(jQuery('li:nth-child(3n+3)'));
    });
    

    where youradd is the class of the div you just created and li:nth-child(3n+3) is… every 3 li element

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search