WordPress.org

Ready to get started?Download WordPress

Forums

Removing comment-field from specific pages (6 posts)

  1. Anders Norén
    Member
    Posted 5 years ago #

    Hi everybody.

    As my blog is not really a blog, I have worked a lot on adjusting various aspects of my theme and WordPress-version to better fit my needs. One of those things was to have comments in ordinary pages. Problem is, some of my pages (Home, About) are not supposed to have comments. I have simply copied the following:

    <?php comments_template(); ?>

    ...From single.php and pasted it in page.php. This naturally enables comments for all of the pages on the site. Question being; how do I disable a few selected pages from having them?

  2. tugbucket
    Member
    Posted 5 years ago #

    http://codex.wordpress.org/Conditional_Tags

    you'll want to use conditional comments calling specific pages.

  3. Dgold
    Member
    Posted 5 years ago #

    Or, I think another way that also could work, get something like the RunPHP plugin
    http://wordpress.org/extend/plugins/runphp/

    Then you should be able to put the template tag function code
    <?php comments_template(); ?>
    right into the body content of your Page (for example probably the last line of your page).

    Instead of putting it in the template

  4. buddha trance
    Member
    Posted 5 years ago #

    Or you could have two page templates, the regular one without comments, and one with comments.

    In your theme folder, you will have
    1 - page.php (as it was before, without <?php comments_template(); ?>)

    2 - page-comments.php (a copy of page.php, but with <?php comments_template(); ?>. At the very top of that template, add this
    to create the template

    <?php /*
    	Template Name: Allow Comments
    */ ?>

    When you create a page that you want comments on, from the attributes select the "Allow Comments" template.

  5. Anders Norén
    Member
    Posted 5 years ago #

    Or you could have two page templates, the regular one without comments, and one with comments.

    Worked like a charm. Thanks buddha, and thanks to the rest of you as well.

  6. Anders Norén
    Member
    Posted 5 years ago #

    Edit: Double

Topic Closed

This topic has been closed to new replies.

About this Topic