2011-08-04 47 views
1

我正在製作一個插件,我希望單個帖子頁面中的評論完全不會被打印。我需要自己查詢數據庫並使用結果打印自己的html。WordPress插件 - 不要在帖子頁面上打印評論

如何讓WordPress不打印評論而不禁用它們?

謝謝

編輯: 作爲一個建議,我使用:

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

什麼也沒有發生,我究竟做錯了什麼?

回答

1

您可以使用comments_template過濾器讓WordPress使用您的插件的模板文件而不是當前主題。

編輯:根據您編輯的代碼:不幸的是,你需要有一個實際的文件,路徑到你$this->comments_template()返回...

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

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

文件plugin_dir/my_comments_template.php必須存在,否則WP倒在默認主題的comments.php。請參閱第911-917行的wp-includes/comment-template.php。

plugin_dir/my_comments_template.php你可以調用`MyPlugin :: do_comments()或類似的東西。我不知道任何其他方式。讓我知道如果你找到更好的方法。

乾杯,克里斯

+0

嗨,:),你可以請看看我的編輯? thanx –

+0

謝謝,但它仍然無法正常工作...我這樣做:apply_filters('comments_template',array($ this,'comments_template'),10,1);在我的類的構造函數,我的函數甚至不叫... –

+1

apply_filters或add_filter?應該是add_filter。 –

相關問題