treehouse : what would you like to learn today?
Web Design Web Development iOS Development

limit comments to one page ...

  • The following is the comments code for my theme ... went ahead and just deleted the code for commenting ... I went to wordpress.org and found this article http://codex.wordpress.org/Commenting_Code ... and instead of just getting ride of/or (commenting out the ) comments all together ... I would rather leave them for the design page ... anywho ... for some reason there is not a whole lot on this subject ... or atleast I have not been able to find it ...





    <?php
    /**
    * The comments template
    *
    * @package WordPress
    * @subpackage Minimatica
    * @since Minimatica 1.0
    */
    ?>

    <div class="entry-comments">

    <?php if ( post_password_required() ) : ?>
    <div id="comments">
    <p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'minimatica' ); ?></p>
    </div><!-- #comments -->
    <?php return; ?>
    <?php endif; ?>

    <?php // You can start editing here -- including this comment! ?>

    <?php if ( ! comments_open() && ! is_page() ) : ?>
    <p class="nocomments"><?php _e( 'Comments are closed.', 'minimatica' ); ?></p>
    <?php endif; ?>

    <?php if ( have_comments() ) : ?>
    <div id="comments">
    <h3 id="comments-title"><?php comments_number( '', __( 'One Response' ), '% ' . __( 'Responses' ) ); ?></h3>
    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
    <div id="nav-above" class="navigation">
    <div class="nav-previous"><?php previous_comments_link( '<span class="meta-nav">&larr;</span> ' . __( 'Older Comments' ) ); ?></div>
    <div class="nav-next"><?php next_comments_link( __( 'Newer Comments' ) . '<span class="meta-nav">&rarr;</span>' ); ?></div>
    <div class="clear"></div>
    </div><!-- .navigation -->
    <?php endif; ?>
    <ol class="commentlist">
    <?php wp_list_comments( array( 'callback' => 'minimatica_comment' ) ); ?>
    </ol><!-- .commentlist -->
    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
    <div id="nav-below" class="navigation">
    <div class="nav-previous"><?php previous_comments_link( '<span class="meta-nav">&larr;</span> ' . __( 'Older Comments' ) ); ?></div>
    <div class="nav-next"><?php next_comments_link( __( 'Newer Comments' ) . '<span class="meta-nav">&rarr;</span>' ); ?></div>
    <div class="clear"></div>
    </div><!-- .navigation -->
    <?php endif; ?>
    </div><!-- #comments -->
    <?php endif; ?>

    <?php
    $post_id = get_the_ID();
    $commenter = wp_get_current_commenter();
    $req = get_option( 'require_name_email' );
    $aria_req = ( $req ? " aria-required='true'" : '' );
    $required_text = '';

    $fields = array(
    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
    '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
    'email' => '<p class="comment-form-email">' . '<label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
    '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
    'url' => '<p class="comment-form-url">' . '<label for="url">' . __( 'Website' ) . '</label>' .
    '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>'
    );

    $defaults = array(
    'fields' => apply_filters( 'comment_form_default_fields', $fields ),
    'comment_field' => '<p class="comment-form-comment"><label for="comment" class="comment-label">' . __( 'Comment' ) . '</label><br /><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
    'comment_notes_before' => '',
    'comment_notes_after' => '',
    );
    ?>

    <?php comment_form( $defaults ); ?>

    </div><!-- .entry-comments -->
  • You could do something like:
    <?php if ( is_page('Design') ) {
    // insert comments code
    } ?>
  • In my last project I did what TheDoc suggested and it works just fine.
  • Sweet ... so to be sure doc ... I put the code at the top of the comments.php and comment out the rest of it ... or leave it as is ?
  • In your page.php you could add:
    <?php if ( is_page('Design') ) {
    comments_template();
    } ?>

    I think that should work if you're using comments.php.
  • the first bit of code you recommended ... do i add that to the top of the comments.php template ... or do I replace a bit of code with what you shared?

    and the second bit of code ... do I add this in addition to the comments bit of code I add? ...

    thanks for your help ...
  • Thanks doc ... I made a back up copy of the template page and comments.php files ... then I added the first bit of code to the comments.php file ... then I deleted everything in the pages.php file between the

    get_header();?> and<?php get_footer(); ?> and replaced it with the second bit of code you gave ... and it is working ... thanks for your help ...
  • now its not showing the post for the about pages ... LOL ...
  • Here is exactly what I have in my "PAGE TEMPLATE"


    get_header(); ?>

    <div id="primary">
    <div id="content" role="main">

    <?php if ( is_page('Design') ) {
    comments_template();
    } ?>
    <?php the_post(); ?>

    <?php get_template_part( 'content', 'page' ); ?>


    </div><!-- #content -->
    </div><!-- #primary -->

    <?php get_footer(); ?>


    All I did was add

    <?php if ( is_page('Design') ) {
    comments_template();
    } ?>


    and I took out

    <?php comments_template( '', true ); ?>


    So now the about page gets its posts ...

    Now I am working on the Design page ... the comments work ... but the page title is below ...
  • Ok ... so what I figured out is this ... the following bit of code

    <?php if ( is_page('Design') ) {
    comments_template();
    } ?>


    has to go after this bit ...

    <?php get_template_part( 'content', 'page' ); ?>


    so now the title shows up above the comments box ...

  • I'm not sure if you've got it sorted - have you figured it out? Do you need anything else?
  • LOL ... yea ... I was just posting everything I did ... so if someone else runs into the same issue ...

    I just made back up copies of the page and comments .php files ... so I could read through the code and see where it might logically go ...

    Thanks for your help doc ...