开发者

WordPress plugins - don't print the comments on a post page

I'm making a plugin where I开发者_开发问答 want the comments in a single post page not to be printed at all. I need to query the database myself and print my own html with the results.

How can I make WordPress to not print the comments, without disabling them?

Thank you

EDIT: as a suggestion, I am using:

apply_filters('comments_template', array($this,'comments_template'), 10, 1);
function comments_template($template){
    $template = '';
    return $template;
}

nothing happens, what am I doing wrong?


You could use the comments_template filter to make WordPress use your plugin's template file rather than the current theme's.

EDIT: based on your edited code: unfortunately you need to have an actual file, the path to which you return in $this->comments_template()...

class MyPlugin{
      //add the filter somewhere...

      function comments_template($template){
           return dirname(__FILE__) . "/my_comments_template.php";
      }
}

The file plugin_dir/my_comments_template.php must exist, otherwise WP falls back on the default theme's comments.php. See wp-includes/comment-template.php on lines 911-917.

In plugin_dir/my_comments_template.php you could call `MyPlugin::do_comments() or something like that. I don't know any other way around this. Let me know if you find a better way.

Cheers, Chris

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜