Support » Fixing WordPress » How to disable comments on pages (all at once)

  • I know there is this option to allow/disallow comments, but I want to allow comments on all posts and disallow comments on all pages.
    Is there a plugin that gives us two options to enable/disable comments?

    It’s for a site a lot of people are going to add pages to, and I’m sure some will forget to turn comments off…

Viewing 10 replies - 1 through 10 (of 10 total)
  • Since no one posted a reply so far…

    Pages are very often used as containers for static information, very different from a blog post. So wouldn’t it be logical to have an option to disable comments for all pages and enable them for blog posts?

    Am I making sense? And could this be done by some plugin or other piece of code?

    The way that I accomplish this is to create a file called page.php and add it to my template directory. This page.php file is identical to my index.php file, except I stripped all the code related to comments.

    For more information on the Template Hierarchy: http://codex.wordpress.org/Template_Hierarchy

    Another way to accomplish this without using a page.php file is to insert the following code into your index.php file:

    <?php
    										/* If we are on a page, then hide comments */
    										if (is_page()) {
    											/* do nothing */
    										} else { 
    
    comments_popup_link('No Comments »', '1 Comment »', '% Comments »');										comments_template();
    										}
    									?>

    Whoa! The formatting got messed up on that last post. Here is a cleaned up version:

    <?php
    /* If we are on a page, then hide comments */
    if (is_page()) {
    /* do nothing */
    } else {
    comments_popup_link('No Comments »', '1 Comment »', '% Comments »');
    comments_template();
    }
    ?>

    is there something else that needs to be done? I added the page.php file and it doesn’t seem to be following that. It’s still doing the same thing it always did. your help would be appreciated

    also, the code the person mention doesn’t seem to work either.

    You could remove the “comments_popup_link” code listed above from your “page.php”. This, technically, wouldn’t stop comments, but it would make them invisible to visitors.

    Parmenti, you need to add the following code at the top of your page.php file to make WordPress recognize it as a template. Then you can choose the template by name when you create or edit a page. If your template is named “Snarfer”, then it would look like this:

    <?php
    /*
    Template Name: Snarfer
    */
    ?>

    This example is taken from a page I found useful, in the section on creating your own page templates: http://codex.wordpress.org/Pages#Page_Templates

    I’m having the opposite problem. I want to allow comments on pages, and have checked such on the Discussion panel of the admin area. However, no comment button appears. Is this a template issue?

    florida-internet-marketing

    (@florida-internet-marketing)

    Thanks this helped me!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to disable comments on pages (all at once)’ is closed to new replies.