/ 设置 10 秒超时 // 每日统计清 0 runtime_set('todaycomments', 0); runtime_set('todayarticles', 0); runtime_set('todayusers', 0); if ($forumlist) { $fidarr = array(); foreach ($forumlist as $fid => $forum) { $fidarr[] = $forum['fid']; } forum_update($fidarr, array('todayposts' => 0, 'todaythreads' => 0)); } // 清理临时附件 attach_gc(); // 当天24点 $today = strtotime(date('Ymd')) + 86400; runtime_set('cron_2_last_date', $today, TRUE); // 往前推8个小时,尽量保证在前一天 升级过来和采集的数据会很卡 // table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } } ?>wp query - how to load the comment template from a plugin|Concepts Of Algorithm

wp query - how to load the comment template from a plugin

admin2025-04-21  1

I want to create custom design for the comments. comments_template() will load the default \comments.php.

i have a file inside my plugin commentsnew.php how can i use this file for comments_template()?

file is getting loaded relative to theme directory.

apply_filters( 'comments_template', string $theme_template ) this completely overrides the template but don't want a complete override but apply only if used.

I want to create custom design for the comments. comments_template() will load the default \comments.php.

i have a file inside my plugin commentsnew.php how can i use this file for comments_template()?

file is getting loaded relative to theme directory.

apply_filters( 'comments_template', string $theme_template ) this completely overrides the template but don't want a complete override but apply only if used.

Share Improve this question edited Aug 29, 2019 at 18:57 asked Aug 29, 2019 at 18:05 user145078user145078 2
  • Can you provide some context for why you would want to do this or the problem that this solves? – Tom J Nowell Commented Aug 29, 2019 at 18:24
  • @TomJNowell to have a review template for the custom post that is created inside a plugin – user145078 Commented Aug 29, 2019 at 18:38
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the comments_template filter to alter which file your CPT will use for comments.

function wpse_plugin_comment_template( $comment_template ) {
     global $post;
     if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
        // leave the standard comments template for standard post types
        return;
     }
     if($post->post_type == 'business'){ // assuming there is a post type called business
        // This is where you would use your commentsnew.php, or review.php
        return dirname(__FILE__) . '/review.php';
     }
}
// throw this into your plugin or your functions.php file to define the custom comments template.
add_filter( "comments_template", "wpse_plugin_comment_template" );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745201161a290061.html

最新回复(0)