最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to properly enable comments form in page template

programmeradmin0浏览0评论

I've applied the following code to enable the comment section in the page template.

<div class="col-md-12">
                <?php while ( have_posts() ) : the_post(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <div class="sec-text wow fadeInUp" data-wow-delay="300ms" data-wow-duration="1000ms">
                            <?php the_content(); ?>
                        </div>
                    </article>
            <div class="col-md-8">
                <?php
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;
                ?>
            </div>
            <?php endwhile; wp_reset_query();?>
            </div>

The comment form is showing directly by this code. User can not able to disable or re-enable the comment form in editor for specific page.

I've applied the following code to enable the comment section in the page template.

<div class="col-md-12">
                <?php while ( have_posts() ) : the_post(); ?>
                    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <div class="sec-text wow fadeInUp" data-wow-delay="300ms" data-wow-duration="1000ms">
                            <?php the_content(); ?>
                        </div>
                    </article>
            <div class="col-md-8">
                <?php
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;
                ?>
            </div>
            <?php endwhile; wp_reset_query();?>
            </div>

The comment form is showing directly by this code. User can not able to disable or re-enable the comment form in editor for specific page.

Share Improve this question asked Mar 9, 2016 at 16:59 Md Jwel MiahMd Jwel Miah 1051 gold badge5 silver badges11 bronze badges 5
  • Did you mean "Discussion" metabox not exist to checklist allow comments? – Jevuska Commented Mar 9, 2016 at 17:17
  • No, the "Discussion" metabox is showing in page editor as well. When I uncheck or check the "Allow comments", this doesn't work. I can not able to disable the comment form by unchecking "Allow comments". – Md Jwel Miah Commented Mar 9, 2016 at 19:22
  • This issue could be from anywhere. I suggest you to check if default page doing like so or you can switch to default theme, then create page template developer.wordpress/themes/template-files-section/… , check if the issue still exist. – Jevuska Commented Mar 10, 2016 at 1:01
  • I checked my comment related functions and I found a cuprite filter. I deleted this filter and now my comment form is working as well. The filter is is - add_filter( 'comments_open', 'my_comments_open', 10, 2 ); function my_comments_open( $open, $post_id ) { $post = get_post( $post_id ); if ( 'page' == $post->post_type ) $open = true; return $open; } – Md Jwel Miah Commented Mar 10, 2016 at 10:11
  • Great!. After you can solve your issue, maybe you need to update your question and mark it as answered. Please take your time to read this wordpress.stackexchange/help/self-answer – Jevuska Commented Mar 10, 2016 at 12:31
Add a comment  | 

2 Answers 2

Reset to default 1

I think it could be a problem with get_comments_number which returns numeric, though theoretically it should test this way too... you could try instead:

if ( comments_open() || have_comments() ) :
    comments_template();
endif;

OR

if ( comments_open() || (get_comments_number() > 0) ) :
    comments_template();
endif;

yes you can do that for specific pages like with a page of page id 9

 //for single page
 if(is_page(9)){ 
  //execute comment template
  comments_template( '', true );

   }

//for single post
if(is_single(9)){
  comments_template( '', true );

} 
发布评论

评论列表(0)

  1. 暂无评论