Wordpress prevent comments on pages

Discussion in 'Web Design and Development' started by Mal, Sep 28, 2011.

  1. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #1
    I am running a small Wordpress blog (still needs lots of content added, but the basics are there), but I want to keep comments enabled for posts, but not for pages. I was told I should remove the code to display the comment block from the page.php file, but I cannot for the life of me figure out what to remove. Here is the page.php file from the Mystique theme that I am using:

    Code:
    <?php /* ATOM/digitalnature */
    
       // The template for the "page" post type. It acts for pages just like single.php does for posts
       // pagename.php, page-slug.php or page-id.php can override it.
    
      get_header();
    ?>
    
      <!-- main content: primary + sidebar(s) -->
      <div id="mask-3" class="clear-block">
       <div id="mask-2">
        <div id="mask-1">
                 
          <!-- primary content -->
          <div id="primary-content">
           <div class="blocks clear-block">
               
            <?php $app->action('before_primary'); ?>
              
            <?php if(have_posts()): ?>
              <div class="posts clear-block">
              <?php while(have_posts()): ?>
                <?php the_post(); ?>
    
                <?php $app->action('before_post'); ?>
    
                <!-- post -->
                <div id="post-<?php the_ID(); ?>" <?php post_class('primary'); ?>>
    
                  <?php if(!$app->post->getMeta('hide_title')): ?>
                  <h1 class="title"><?php the_title(); ?></h1>
                  <?php endif; ?>
    
                  <div class="clear-block">
                    <?php the_content(); ?>
                  </div>
    
                  <?php $app->post->paginate(); ?>
    
                  <?php $app->controls('post-edit'); ?>
                </div>
                <!-- /post -->
                <?php $app->action('after_post'); ?>
    
              <?php endwhile; ?>
              </div>
    
              <?php $app->template('meta'); ?>
    
            <?php else: ?>
              <h1 class="title error"><?php _ae('Oops, nothing here :('); ?></h1>
            <?php endif; ?>
    
            <?php $app->action('after_primary'); ?>
    
           </div>
          </div>
          <!-- /primary content -->
    
          <?php get_sidebar(); ?>
        </div>
       </div>
      </div>
      <!-- /main content -->
    
    <?php get_footer(); ?>
    My site is thebeardednerd.com, and I don't want comments to appear on the Contact Me or Services and Rates pages from the top nav.

    Please help!

    jW
     
  2. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #2
    PHP:
                <?php $app->action('after_post'); ?>
    Is the one calling it. But this must be a really old version of the theme. This should now be handled with a call to comments_template();

    You can remove the above or update and remove comments_template();
     
  3. Mal thread starter macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #3
    Yeah, the theme is actually not that great in terms of proper Wordpress code, as far as I can tell. I tried both commenting out and deleting that line from the template, but it didn't seem to work. I'll try again.

    Anyone have a suggestion for a good up-to-date theme with a similar design that I could be using instead? I particularly like the header and menu part of this theme, although I do intend to have a custom logo eventually (I have a logo contest running on Facebook right now, though it's been a little dry).

    jW
     
  4. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #4
  5. glutenenvy macrumors regular

    glutenenvy

    Joined:
    Sep 6, 2011
    Location:
    WA
    #5
    Ok but why not make it easy on yourself? Uncheck the allow comments and allow pings from each page as you create them. You have the benefit of not having to hack up a theme every time it is updated or you try a different theme.

    If you do need to hack up a theme, do make sure you are using child themes and not making changes to the original. Themes are often updated.
     
  6. Mal thread starter macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #6
    I'm using Mystique 3.1, so a newer version than the one you linked to, and not the lite version.

    Not sure about paying for a theme at this point, but I'll look those over.

    ----------

    That would be my preference, but the comments checkbox does not appear when I'm creating or editing a page. Not sure why. I am using a child theme, btw.

    jW
     
  7. brisbaneguy29, Sep 28, 2011
    Last edited by a moderator: Oct 2, 2011

    brisbaneguy29 macrumors 6502

    brisbaneguy29

    Joined:
    Nov 27, 2007
    Location:
    Brisbane
    #7
    Might be a silly question, but before you go diving through the code, Wordpress usually lets you control comments per page through the dashboard. Open the pages through the dashboard and scroll down under the section where your type the content and you should see a section called Discussion. Just tick / untick the pages your do or don't want to see comments.

    [​IMG]

    If you don't see the discussion section check the section is visible through your screen option panel in the top right.

    [​IMG]

    While some themes may turn this off, just check here before you go scrubbing through the code.
     
  8. Mal thread starter macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #8
    Thanks! That did the trick!

    jW
     

Share This Page