logo

$40
change comments fields in Thematic

Working on a Thematic child theme and I need to be able to add the field 'Organisation' (ie company) to the required fields in the add comment form, and then display the organisation name under the avatar / user name in the comments, ideally linking the organisation name to the url rather than the users name.

I've gotten as far as installing this plugin: http://www.ideashower.com/our_solutions/wordpress-plugin-extra-comment-fields/

and adding this code to the comments.php file:
<div id="form-section-org" class="form-section">
<div class="form-label"><label for="Organisation">Organisation</label></div>
<div class="form-input"><input id="Organisation" name="Organisation" type="text" size="22" maxlength="80" tabindex="6"/></div>
</div>


but am at a loss as to how to show the inputted field in the comments list.

anyone help please?

Dave Smith | 03/26/10 at 7:54am | Edit


(2) Possible Answers Submitted...

  • avatar
    Last edited:
    03/26/10
    8:26am
    Dan Davies says:

    Make sure you have added 'Organisation' as an extra variable on the Extra Comments Fields settings page.

    Once you have done that, edit your comments.php file. There should be a chunk of code that begins with

    <?php foreach ($comments as $comment) : ?>


    Beneath that should be the various tags for comment_date, comment_author, etc.

    Simply add the code below to show the user's organisation.

    <?php print $comment->Organisation; ?>


    If your comments.php doesn't have the foreach ($comments as $comment) section, you might want to modify the code of the comments.php file to this:

    <ol class=”commentlist”>

    <?php foreach ($comments as $comment) : ?>

    <li <?php echo $oddcomment; ?>id=”comment-<?php comment_ID() ?>”>
    <?php echo get_avatar( $comment, 32 ); ?>
    <?php print $comment->Organisation; ?>
    <?php comment_author_link() ?> Says:
    <?php if ($comment->comment_approved == ‘0′) : ?>
    Your comment is awaiting moderation.
    <?php endif; ?>
    <br />

    <small class=”commentmetadata”><a href=”#comment-<?php comment_ID() ?>” title=”"><?php comment_date(’F jS, Y’) ?> at <?php comment_time() ?></a> <?php edit_comment_link(’edit’,’ ‘,”); ?></small>

    <?php comment_text() ?>


    </li>

    <?php
    /* Changes every other comment to a different class */
    $oddcomment = ( empty( $oddcomment ) ) ? ‘class=”alt” ‘ : ”;
    ?>

    <?php endforeach; /* end for each comment */ ?>

    </ol>

    • 03/26/10 10:04am

      Dave Smith says:

      ok i'm struggling here so here's the complete thematic comments.php code:

      <?php thematic_abovecomments() ?>
      <div id="comments">
      <?php
      $req = get_option('require_name_email'); // Checks if fields are required.
      if ( 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )
      die ( 'Please do not load this page directly. Thanks!' );
      if ( ! empty($post->post_password) ) :
      if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :
      ?>
      <div class="nopassword"><?php _e('This post is password protected. Enter the password to view any comments.', 'thematic') ?></div>
      </div><!-- .comments -->
      <?php
      return;
      endif;
      endif;
      ?>

      <?php if ( have_comments() ) : ?>

      <?php /* numbers of pings and comments */
      $ping_count = $comment_count = 0;
      foreach ( $comments as $comment )
      get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;
      ?>

      <?php if ( ! empty($comments_by_type['comment']) ) : ?>

      <?php thematic_abovecommentslist() ?>

      <div id="comments-list" class="comments">
      <h3><?php printf($comment_count > 1 ? __(thematic_multiplecomments_text(), 'thematic') : __(thematic_singlecomment_text(), 'thematic'), $comment_count) ?></h3>

      <ol>
      <?php wp_list_comments(list_comments_arg()); ?>
      </ol>

      <div id="comments-nav-below" class="comment-navigation">
      <div class="paginated-comments-links"><?php paginate_comments_links(); ?></div>
      </div>

      </div><!-- #comments-list .comments -->

      <?php thematic_belowcommentslist() ?>

      <?php endif; /* if ( $comment_count ) */ ?>

      <?php if ( ! empty($comments_by_type['pings']) ) : ?>

      <?php thematic_abovetrackbackslist() ?>

      <div id="trackbacks-list" class="comments">
      <h3><?php printf($ping_count > 1 ? __('<span>%d</span> Trackbacks', 'thematic') : __('<span>One</span> Trackback', 'thematic'), $ping_count) ?></h3>

      <ol>
      <?php wp_list_comments('type=pings&callback=thematic_pings'); ?>
      </ol>

      </div><!-- #trackbacks-list .comments -->

      <?php thematic_belowtrackbackslist() ?>

      <?php endif /* if ( $ping_count ) */ ?>
      <?php endif /* if ( $comments ) */ ?>

      <?php if ( 'open' == $post->comment_status ) : ?>
      <div id="respond">
      <h3><?php comment_form_title( __(thematic_postcomment_text(), 'thematic'), __(thematic_postreply_text(), 'thematic') ); ?></h3>

      <div id="cancel-comment-reply"><?php cancel_comment_reply_link() ?></div>

      <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
      <p id="login-req"><?php printf(__('You must be <a href="%s" title="Log in">logged in</a> to post a comment.', 'thematic'),
      get_option('siteurl') . '/wp-login.php?redirect_to=' . get_permalink() ) ?></p>

      <?php else : ?>
      <div class="formcontainer">

      <?php thematic_abovecommentsform() ?>

      <form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">

      <?php if ( $user_ID ) : ?>
      <p id="login"><?php printf(__('<span class="loggedin">Logged in as <a href="%1$s" title="Logged in as %2$s">%2$s</a>.</span> <span class="logout"><a href="%3$s" title="Log out of this account">Log out?</a></span>', 'thematic'),
      get_option('siteurl') . '/wp-admin/profile.php',
      wp_specialchars($user_identity, true),
      wp_logout_url(get_permalink()) ) ?></p>

      <?php else : ?>

      <p id="comment-notes"><?php _e('Your email is never published nor shared.', 'thematic') ?> <?php if ($req) _e('Required fields are marked <span class="required">*</span>', 'thematic') ?></p>

      <div id="form-section-author" class="form-section">
      <div class="form-label"><label for="author"><?php _e('Name', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="author" name="author" type="text" value="<?php echo $comment_author ?>" size="30" maxlength="20" tabindex="3" /></div>
      </div><!-- #form-section-author .form-section -->

      <div id="form-section-email" class="form-section">
      <div class="form-label"><label for="email"><?php _e('Email', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="email" name="email" type="text" value="<?php echo $comment_author_email ?>" size="30" maxlength="50" tabindex="4" /></div>
      </div><!-- #form-section-email .form-section -->

      <div id="form-section-url" class="form-section">
      <div class="form-label"><label for="url"><?php _e('Website', 'thematic') ?></label></div>
      <div class="form-input"><input id="url" name="url" type="text" value="<?php echo $comment_author_url ?>" size="30" maxlength="50" tabindex="5" /></div>

      </div><!-- #form-section-url .form-section -->
      <div id="form-section-org" class="form-section">
      <div class="form-label"><label for="Organisation">Organisation</label></div>
      <div class="form-input"><input id="Organisation" name="Organisation" type="text" size="22" maxlength="80" tabindex="6"/></div>
      </div>

      <?php endif /* if ( $user_ID ) */ ?>

      <div id="form-section-comment" class="form-section">
      <div class="form-label"><label for="comment"><?php _e(thematic_commentbox_text(), 'thematic') ?></label></div>
      <div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6"></textarea></div>
      </div><!-- #form-section-comment .form-section -->

      <div id="form-allowed-tags" class="form-section">
      <p><span><?php _e('You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', 'thematic') ?></span>
      <?php echo allowed_tags(); ?>
      </p>
      </div>

      <?php do_action('comment_form', $post->ID); ?>

      <div class="form-submit"><input id="submit" name="submit" type="submit" value="<?php _e(thematic_commentbutton_text(), 'thematic') ?>" tabindex="7" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></div>

      <?php comment_id_fields(); ?>

      </form><!-- #commentform -->

      <?php thematic_belowcommentsform() ?>

      </div><!-- .formcontainer -->
      <?php endif /* if ( get_option('comment_registration') && !$user_ID ) */ ?>

      </div><!-- #respond -->
      <?php endif /* if ( 'open' == $post->comment_status ) */ ?>

      </div><!-- #comments -->
      <?php thematic_belowcomments() ?>


      any chance you could paste a completed revision for me?

    • 03/26/10 10:14am

      Dan Davies says:

      Give this a try

      <?php thematic_abovecomments() ?>
      <div id="comments">
      <?php
      $req = get_option('require_name_email'); // Checks if fields are required.

      if ( 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )

      die ( 'Please do not load this page directly. Thanks!' );

      if ( ! empty($post->post_password) ) :

      if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :

      ?>

      <div class="nopassword"><?php _e('This post is password protected. Enter the password to view any comments.', 'thematic') ?></div>

      </div><!-- .comments -->

      <?php

      return;

      endif;

      endif;

      ?>



      <?php if ( have_comments() ) : ?>



      <?php /* numbers of pings and comments */

      $ping_count = $comment_count = 0;

      foreach ( $comments as $comment )

      get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;

      ?>



      <?php if ( ! empty($comments_by_type['comment']) ) : ?>



      <?php thematic_abovecommentslist() ?>



      <div id="comments-list" class="comments">

      <h3><?php printf($comment_count > 1 ? __(thematic_multiplecomments_text(), 'thematic') : __(thematic_singlecomment_text(), 'thematic'), $comment_count) ?></h3>



      <ol>
      <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
      <?php echo get_avatar( $comment, 32 ); ?>
      <?php print $comment->Organisation; ?>
      <?php comment_author_link() ?> Says:
      <?php if ($comment->comment_approved == '0') : ?>
      Your comment is awaiting moderation.
      <?php endif; ?>
      <br />
      <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit',' ',''); ?></small>
      <?php comment_text() ?>
      </li>
      <?php
      /* Changes every other comment to a different class */
      $oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
      ?>
      </ol>



      <div id="comments-nav-below" class="comment-navigation">

      <div class="paginated-comments-links"><?php paginate_comments_links(); ?></div>

      </div>



      </div><!-- #comments-list .comments -->



      <?php thematic_belowcommentslist() ?>



      <?php endif; /* if ( $comment_count ) */ ?>



      <?php if ( ! empty($comments_by_type['pings']) ) : ?>



      <?php thematic_abovetrackbackslist() ?>



      <div id="trackbacks-list" class="comments">

      <h3><?php printf($ping_count > 1 ? __('<span>%d</span> Trackbacks', 'thematic') : __('<span>One</span> Trackback', 'thematic'), $ping_count) ?></h3>



      <ol>

      <?php wp_list_comments('type=pings&callback=thematic_pings'); ?>

      </ol>



      </div><!-- #trackbacks-list .comments -->



      <?php thematic_belowtrackbackslist() ?>



      <?php endif /* if ( $ping_count ) */ ?>

      <?php endif /* if ( $comments ) */ ?>



      <?php if ( 'open' == $post->comment_status ) : ?>

      <div id="respond">

      <h3><?php comment_form_title( __(thematic_postcomment_text(), 'thematic'), __(thematic_postreply_text(), 'thematic') ); ?></h3>



      <div id="cancel-comment-reply"><?php cancel_comment_reply_link() ?></div>



      <?php if ( get_option('comment_registration') && !$user_ID ) : ?>

      <p id="login-req"><?php printf(__('You must be <a href="%s" title="Log in">logged in</a> to post a comment.', 'thematic'),

      get_option('siteurl') . '/wp-login.php?redirect_to=' . get_permalink() ) ?></p>



      <?php else : ?>

      <div class="formcontainer">



      <?php thematic_abovecommentsform() ?>



      <form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">



      <?php if ( $user_ID ) : ?>

      <p id="login"><?php printf(__('<span class="loggedin">Logged in as <a href="%1$s" title="Logged in as %2$s">%2$s</a>.</span> <span class="logout"><a href="%3$s" title="Log out of this account">Log out?</a></span>', 'thematic'),

      get_option('siteurl') . '/wp-admin/profile.php',

      wp_specialchars($user_identity, true),

      wp_logout_url(get_permalink()) ) ?></p>



      <?php else : ?>



      <p id="comment-notes"><?php _e('Your email is never published nor shared.', 'thematic') ?> <?php if ($req) _e('Required fields are marked <span class="required">*</span>', 'thematic') ?></p>



      <div id="form-section-author" class="form-section">

      <div class="form-label"><label for="author"><?php _e('Name', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>

      <div class="form-input"><input id="author" name="author" type="text" value="<?php echo $comment_author ?>" size="30" maxlength="20" tabindex="3" /></div>

      </div><!-- #form-section-author .form-section -->



      <div id="form-section-email" class="form-section">

      <div class="form-label"><label for="email"><?php _e('Email', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>

      <div class="form-input"><input id="email" name="email" type="text" value="<?php echo $comment_author_email ?>" size="30" maxlength="50" tabindex="4" /></div>

      </div><!-- #form-section-email .form-section -->



      <div id="form-section-url" class="form-section">

      <div class="form-label"><label for="url"><?php _e('Website', 'thematic') ?></label></div>

      <div class="form-input"><input id="url" name="url" type="text" value="<?php echo $comment_author_url ?>" size="30" maxlength="50" tabindex="5" /></div>



      </div><!-- #form-section-url .form-section -->

      <div id="form-section-org" class="form-section">

      <div class="form-label"><label for="Organisation">Organisation</label></div>

      <div class="form-input"><input id="Organisation" name="Organisation" type="text" size="22" maxlength="80" tabindex="6"/></div>

      </div>



      <?php endif /* if ( $user_ID ) */ ?>



      <div id="form-section-comment" class="form-section">

      <div class="form-label"><label for="comment"><?php _e(thematic_commentbox_text(), 'thematic') ?></label></div>

      <div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6"></textarea></div>

      </div><!-- #form-section-comment .form-section -->



      <div id="form-allowed-tags" class="form-section">

      <p><span><?php _e('You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', 'thematic') ?></span>

      <?php echo allowed_tags(); ?>

      </p>

      </div>



      <?php do_action('comment_form', $post->ID); ?>



      <div class="form-submit"><input id="submit" name="submit" type="submit" value="<?php _e(thematic_commentbutton_text(), 'thematic') ?>" tabindex="7" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></div>



      <?php comment_id_fields(); ?>



      </form><!-- #commentform -->



      <?php thematic_belowcommentsform() ?>



      </div><!-- .formcontainer -->

      <?php endif /* if ( get_option('comment_registration') && !$user_ID ) */ ?>



      </div><!-- #respond -->

      <?php endif /* if ( 'open' == $post->comment_status ) */ ?>



      </div><!-- #comments -->

      <?php thematic_belowcomments() ?>

    • 03/26/10 11:30am

      Dave Smith says:

      not worked: I'm getting:

      ----------------------
      dave Says:
      March 26th, 2010 at 3:26 pm

      this is my comment
      ----------------------

      no org name, no link, just the above plus gravatar...

      any ideas?

    • 03/26/10 11:33am

      Dan Davies says:

      Is the variable you've added to the extra comments fields called "Organisation" (same spelling, with the upper-case o?)

    • 03/26/10 11:35am

      Dan Davies says:

      Ah, sorry. Find:

      <?php print $comment->Organisation; ?>


      Replace with:

      <?php print $comment->extra_Organisation; ?>


      Although change it to _organisation if you use a lower-case o in the variable you set up in the settings.

    • 03/26/10 11:59am

      Dave Smith says:

      tried that, with correct capitalisation, no joy. additionally, it's now only showing the most recent comment, and not showing the previous comments (although it's showing the comment count correctly).

      ?

    • 03/26/10 12:09pm

      Dan Davies says:

      Darn colons.

      This should be it.

      <?php thematic_abovecomments() ?>
      <div id="comments">
      <?php
      $req = get_option('require_name_email'); // Checks if fields are required.
      if ( 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )
      die ( 'Please do not load this page directly. Thanks!' );
      if ( ! empty($post->post_password) ) :
      if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :
      ?>

      <div class="nopassword"><?php _e('This post is password protected. Enter the password to view any comments.', 'thematic') ?></div>
      </div><!-- .comments -->

      <?php
      return;
      endif;
      endif;
      ?>

      <?php if ( have_comments() ) : ?>
      <?php /* numbers of pings and comments */
      $ping_count = $comment_count = 0;
      foreach ( $comments as $comment )
      get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;
      ?>

      <?php if ( ! empty($comments_by_type['comment']) ) : ?>
      <?php thematic_abovecommentslist() ?>
      <div id="comments-list" class="comments">
      <h3><?php printf($comment_count > 1 ? __(thematic_multiplecomments_text(), 'thematic') : __(thematic_singlecomment_text(), 'thematic'), $comment_count) ?></h3>
      <ol>
      <?php foreach ($comments as $comment) : ?>
      <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>">
      <?php echo get_avatar( $comment, 32 ); ?>
      <?php print $comment->extra_Organisation; ?>
      <?php comment_author_link() ?> Says:
      <?php if ($comment->comment_approved == '0') : ?>
      Your comment is awaiting moderation.
      <?php endif; ?>
      <br />
      <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit',' ',''); ?></small>
      <?php comment_text() ?>
      </li>
      <?php
      /* Changes every other comment to a different class */
      $oddcomment = ( empty( $oddcomment ) ) ? 'class="alt" ' : '';
      ?>
      <?php endforeach; /* end for each comment */ ?>
      </ol>

      <div id="comments-nav-below" class="comment-navigation">
      <div class="paginated-comments-links"><?php paginate_comments_links(); ?></div>
      </div>
      </div><!-- #comments-list .comments -->
      <?php thematic_belowcommentslist() ?>
      <?php endif; /* if ( $comment_count ) */ ?>
      <?php if ( ! empty($comments_by_type['pings']) ) : ?>
      <?php thematic_abovetrackbackslist() ?>

      <div id="trackbacks-list" class="comments">
      <h3><?php printf($ping_count > 1 ? __('<span>%d</span> Trackbacks', 'thematic') : __('<span>One</span> Trackback', 'thematic'), $ping_count) ?></h3>
      <ol>
      <?php wp_list_comments('type=pings&callback=thematic_pings'); ?>
      </ol>
      </div><!-- #trackbacks-list .comments -->
      <?php thematic_belowtrackbackslist() ?>
      <?php endif /* if ( $ping_count ) */ ?>
      <?php endif /* if ( $comments ) */ ?>

      <?php if ( 'open' == $post->comment_status ) : ?>
      <div id="respond">
      <h3><?php comment_form_title( __(thematic_postcomment_text(), 'thematic'), __(thematic_postreply_text(), 'thematic') ); ?></h3>
      <div id="cancel-comment-reply"><?php cancel_comment_reply_link() ?></div>
      <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
      <p id="login-req"><?php printf(__('You must be <a href="%s" title="Log in">logged in</a> to post a comment.', 'thematic'),
      get_option('siteurl') . '/wp-login.php?redirect_to=' . get_permalink() ) ?></p>
      <?php else : ?>
      <div class="formcontainer">
      <?php thematic_abovecommentsform() ?>
      <form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">
      <?php if ( $user_ID ) : ?>
      <p id="login"><?php printf(__('<span class="loggedin">Logged in as <a href="%1$s" title="Logged in as %2$s">%2$s</a>.</span> <span class="logout"><a href="%3$s" title="Log out of this account">Log out?</a></span>', 'thematic'),
      get_option('siteurl') . '/wp-admin/profile.php',
      wp_specialchars($user_identity, true),
      wp_logout_url(get_permalink()) ) ?></p>
      <?php else : ?>
      <p id="comment-notes"><?php _e('Your email is never published nor shared.', 'thematic') ?> <?php if ($req) _e('Required fields are marked <span class="required">*</span>', 'thematic') ?></p>
      <div id="form-section-author" class="form-section">
      <div class="form-label"><label for="author"><?php _e('Name', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="author" name="author" type="text" value="<?php echo $comment_author ?>" size="30" maxlength="20" tabindex="3" /></div>
      </div><!-- #form-section-author .form-section -->
      <div id="form-section-email" class="form-section">
      <div class="form-label"><label for="email"><?php _e('Email', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="email" name="email" type="text" value="<?php echo $comment_author_email ?>" size="30" maxlength="50" tabindex="4" /></div>
      </div><!-- #form-section-email .form-section -->
      <div id="form-section-url" class="form-section">
      <div class="form-label"><label for="url"><?php _e('Website', 'thematic') ?></label></div>
      <div class="form-input"><input id="url" name="url" type="text" value="<?php echo $comment_author_url ?>" size="30" maxlength="50" tabindex="5" /></div>
      </div><!-- #form-section-url .form-section -->
      <div id="form-section-org" class="form-section">
      <div class="form-label"><label for="Organisation">Organisation</label></div>
      <div class="form-input"><input id="Organisation" name="Organisation" type="text" size="22" maxlength="80" tabindex="6"/></div>
      </div>
      <?php endif /* if ( $user_ID ) */ ?>
      <div id="form-section-comment" class="form-section">
      <div class="form-label"><label for="comment"><?php _e(thematic_commentbox_text(), 'thematic') ?></label></div>
      <div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6"></textarea></div>
      </div><!-- #form-section-comment .form-section -->
      <div id="form-allowed-tags" class="form-section">
      <p><span><?php _e('You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', 'thematic') ?></span>
      <?php echo allowed_tags(); ?>
      </p>
      </div>
      <?php do_action('comment_form', $post->ID); ?>
      <div class="form-submit"><input id="submit" name="submit" type="submit" value="<?php _e(thematic_commentbutton_text(), 'thematic') ?>" tabindex="7" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></div>
      <?php comment_id_fields(); ?>
      </form><!-- #commentform -->
      <?php thematic_belowcommentsform() ?>
      </div><!-- .formcontainer -->
      <?php endif /* if ( get_option('comment_registration') && !$user_ID ) */ ?>
      </div><!-- #respond -->
      <?php endif /* if ( 'open' == $post->comment_status ) */ ?>
      </div><!-- #comments -->
      <?php thematic_belowcomments() ?>

    • 03/26/10 1:37pm

      Dave Smith says:

      not working. beginning to wonder whether there's a problem with the plugin. for a potentially higher fee, is there a way of doing this plugin free?

    • 03/26/10 1:39pm

      Dan Davies says:

      Could you message me login details for your account, and ensure that I can edit template files from the dashboard? I'll see if I can fix it without us to-ing and fro-ing.

    • 03/26/10 1:44pm

      Dave Smith says:

      from the plugin comments:

      Yeah it works fine in 2.9.1 if you follow Marco’s + Scott Shumaker’s instructions.
      1) replace in function ecf_getComments($comments, $post_id):
      $result = $wpdb->get_results(”SELECT xc.comment_ID, “.ecf_qryStr($fields).”
      FROM wp_comments c, wp_comments_extra xc
      WHERE c.comment_post_ID = ‘$post_id’ AND c.comment_ID = xc.comment_ID”);

      with:
      $wpdb->xc = $wpdb->prefix . ‘comments_extra’;
      $wpdb->c = $wpdb->prefix . ‘comments’;

      $sql = “SELECT xc.comment_ID, “.ecf_qryStr($fields).” FROM $wpdb->c c, $wpdb->xc xc WHERE c.comment_approved = 1 AND c.comment_post_ID = ‘$post_id’ AND c.comment_ID = xc.comment_ID”;

      $result = $wpdb->get_results($sql);

      2) Comment out line 176

      3) Manually add the “wp_comments_extra” table in your phpmyadmin and insert “comment_id” as a BIGINT and Primary Key. Then add a second field named with your label name (ex: age)

      Then, changes will be kept in Settings->Extra Comment Fields
      You will be able to insert the value, as shown in the article, by doing “extra_question; ?>” (remove space between ph and p to make it work lol)

      Yay =D


      tried doing this, it broke the plugin (and site) so it's not just a code issue. seems when you add a new comment field, it doesn't save to the dbase, but doing the above fixes breaks the plugin giving white screen. this is why i think i may need a fix which is independent of the plugin.

  • avatar
    Last edited:
    03/30/10
    4:38am
    Buzu B says:

    Ok, so there is really no 'easy' way to do this, since the comments table has only the fields it needs in order to work. One solution is to save the organization name as part of one of those fields. For example, before sending the comment contents we can append the value of the organization field to the comment using a defined format like

    [_extra_org]field value[/_extra_org]

    later when retrieving the comments we just filter the comment searching for our especial format. We pull it out from the comment and just return the comment.

    Do you want to give this a try? tell me and we'll work step by step.

    • 03/26/10 3:10pm

      Buzu B says:

      Ok, I guess I will yous post my solution.

      First think you have to do is get rid of the plug in. Is not working.

      Next, go to your comments.php on thematic's folder and edit si it looks like this:


      <?php thematic_abovecomments() ?>
      <div id="comments">
      <?php
      $req = get_option('require_name_email'); // Checks if fields are required.
      if ( 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )
      die ( 'Please do not load this page directly. Thanks!' );
      if ( ! empty($post->post_password) ) :
      if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) :
      ?>
      <div class="nopassword"><?php _e('This post is password protected. Enter the password to view any comments.', 'thematic') ?></div>
      </div><!-- .comments -->
      <?php
      return;
      endif;
      endif;
      ?>

      <?php if ( have_comments() ) : ?>

      <?php /* numbers of pings and comments */
      $ping_count = $comment_count = 0;
      foreach ( $comments as $comment )
      get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;
      ?>

      <?php if ( ! empty($comments_by_type['comment']) ) : ?>

      <?php thematic_abovecommentslist() ?>

      <div id="comments-list" class="comments">
      <h3><?php printf($comment_count > 1 ? __(thematic_multiplecomments_text(), 'thematic') : __(thematic_singlecomment_text(), 'thematic'), $comment_count) ?></h3>

      <ol>
      <?php //wp_list_comments(list_comments_arg());
      foreach($comments as $comment){
      //ADED BY BUZU
      if (strpos($comment->comment_content,'[_extra_org]')!== false) {
      list($comment_cont, $org) = split("\[_extra_org\]", $comment->comment_content);
      $org = split("\[\/_extra_org\]", $org);
      }else{
      $comment_cont = $comment->comment_content;
      $org = '';
      }
      ?>
      <h3> <?php echo $comment->comment_author; ?> said: </h3>
      <p>Organization: <?php echo $org[0]; ?></p>
      <p> <?php echo $comment_cont; ?></p>
      <?php
      //END ADDED BY BUZU
      }
      ?>
      </ol>

      <div id="comments-nav-below" class="comment-navigation">
      <div class="paginated-comments-links"><?php paginate_comments_links(); ?></div>
      </div>

      </div><!-- #comments-list .comments -->

      <?php thematic_belowcommentslist() ?>

      <?php endif; /* if ( $comment_count ) */ ?>

      <?php if ( ! empty($comments_by_type['pings']) ) : ?>

      <?php thematic_abovetrackbackslist() ?>

      <div id="trackbacks-list" class="comments">
      <h3><?php printf($ping_count > 1 ? __('<span>%d</span> Trackbacks', 'thematic') : __('<span>One</span> Trackback', 'thematic'), $ping_count) ?></h3>

      <ol>
      <?php wp_list_comments('type=pings&callback=thematic_pings'); ?>
      </ol>

      </div><!-- #trackbacks-list .comments -->

      <?php thematic_belowtrackbackslist() ?>

      <?php endif /* if ( $ping_count ) */ ?>
      <?php endif /* if ( $comments ) */ ?>

      <?php if ( 'open' == $post->comment_status ) : ?>
      <div id="respond">
      <h3><?php comment_form_title( __(thematic_postcomment_text(), 'thematic'), __(thematic_postreply_text(), 'thematic') ); ?></h3>

      <div id="cancel-comment-reply"><?php cancel_comment_reply_link() ?></div>

      <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
      <p id="login-req"><?php printf(__('You must be <a href="%s" title="Log in">logged in</a> to post a comment.', 'thematic'),
      get_option('siteurl') . '/wp-login.php?redirect_to=' . get_permalink() ) ?></p>

      <?php else : ?>
      <div class="formcontainer">

      <?php thematic_abovecommentsform() ?>

      <form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post">

      <?php if ( $user_ID ) : ?>
      <p id="login"><?php printf(__('<span class="loggedin">Logged in as <a href="%1$s" title="Logged in as %2$s">%2$s</a>.</span> <span class="logout"><a href="%3$s" title="Log out of this account">Log out?</a></span>', 'thematic'),
      get_option('siteurl') . '/wp-admin/profile.php',
      wp_specialchars($user_identity, true),
      wp_logout_url(get_permalink()) ) ?></p>

      <?php else : ?>

      <p id="comment-notes"><?php _e('Your email is never published nor shared.', 'thematic') ?> <?php if ($req) _e('Required fields are marked <span class="required">*</span>', 'thematic') ?></p>

      <div id="form-section-author" class="form-section">
      <div class="form-label"><label for="author"><?php _e('Name', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="author" name="author" type="text" value="<?php echo $comment_author ?>" size="30" maxlength="20" tabindex="3" /></div>
      </div><!-- #form-section-author .form-section -->


      <div id="form-section-org" class="form-section">
      <div class="form-label"><label for="org"><?php _e('Org', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="org" name="org" type="text" value="<?php ?>" size="30" maxlength="50" tabindex="4" /></div>
      </div>


      <div id="form-section-email" class="form-section">
      <div class="form-label"><label for="email"><?php _e('Email', 'thematic') ?></label> <?php if ($req) _e('<span class="required">*</span>', 'thematic') ?></div>
      <div class="form-input"><input id="email" name="email" type="text" value="<?php echo $comment_author_email ?>" size="30" maxlength="50" tabindex="4" /></div>
      </div><!-- #form-section-email .form-section -->

      <div id="form-section-url" class="form-section">
      <div class="form-label"><label for="url"><?php _e('Website', 'thematic') ?></label></div>
      <div class="form-input"><input id="url" name="url" type="text" value="<?php echo $comment_author_url ?>" size="30" maxlength="50" tabindex="5" /></div>
      </div><!-- #form-section-url .form-section -->

      <?php endif /* if ( $user_ID ) */ ?>

      <div id="form-section-comment" class="form-section">
      <div class="form-label"><label for="comment"><?php _e(thematic_commentbox_text(), 'thematic') ?></label></div>
      <div class="form-textarea"><textarea id="comment" name="comment" cols="45" rows="8" tabindex="6"></textarea></div>
      </div><!-- #form-section-comment .form-section -->

      <div id="form-allowed-tags" class="form-section">
      <p><span><?php _e('You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:', 'thematic') ?></span>
      <?php echo allowed_tags(); ?>
      </p>
      </div>

      <?php do_action('comment_form', $post->ID); ?>

      <div class="form-submit"><input id="submit" name="submit" type="submit" value="<?php _e(thematic_commentbutton_text(), 'thematic') ?>" tabindex="7" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" /></div>

      <?php comment_id_fields(); ?>

      </form><!-- #commentform -->

      <?php thematic_belowcommentsform() ?>

      </div><!-- .formcontainer -->
      <?php endif /* if ( get_option('comment_registration') && !$user_ID ) */ ?>

      </div><!-- #respond -->
      <?php endif /* if ( 'open' == $post->comment_status ) */ ?>

      </div><!-- #comments -->
      <?php thematic_belowcomments() ?>


      Note that the code I added has been enclosed within comments that indicate where my editing starts and when it ends. I also added a field on the form, but you had done that before as well.

      Next, you will have to edit your wp-comments-post.php located in your main wordpress folder. Change it so it looks like this:


      <?php
      /**
      * Handles Comment Post to WordPress and prevents duplicate comment posting.
      *
      * @package WordPress
      */

      if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
      header('Allow: POST');
      header('HTTP/1.1 405 Method Not Allowed');
      header('Content-Type: text/plain');
      exit;
      }

      /** Sets up the WordPress Environment. */
      require( dirname(__FILE__) . '/wp-load.php' );

      nocache_headers();

      $comment_post_ID = (int) $_POST['comment_post_ID'];

      $status = $wpdb->get_row( $wpdb->prepare("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) );

      if ( empty($status->comment_status) ) {
      do_action('comment_id_not_found', $comment_post_ID);
      exit;
      } elseif ( !comments_open($comment_post_ID) ) {
      do_action('comment_closed', $comment_post_ID);
      wp_die( __('Sorry, comments are closed for this item.') );
      } elseif ( in_array($status->post_status, array('draft', 'pending') ) ) {
      do_action('comment_on_draft', $comment_post_ID);
      exit;
      } else {
      do_action('pre_comment_on_post', $comment_post_ID);
      }

      $comment_author = ( isset($_POST['author']) ) ? trim(strip_tags($_POST['author'])) : null;
      $comment_author_email = ( isset($_POST['email']) ) ? trim($_POST['email']) : null;
      $comment_author_url = ( isset($_POST['url']) ) ? trim($_POST['url']) : null;
      $comment_content = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;

      //ADED BY BUZU just this next line
      $comment_org = ( isset($_POST['org']) ) ? trim($_POST['org']) : null;

      // If the user is logged in
      $user = wp_get_current_user();
      if ( $user->ID ) {
      if ( empty( $user->display_name ) )
      $user->display_name=$user->user_login;
      $comment_author = $wpdb->escape($user->display_name);
      $comment_author_email = $wpdb->escape($user->user_email);
      $comment_author_url = $wpdb->escape($user->user_url);
      if ( current_user_can('unfiltered_html') ) {
      if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
      kses_remove_filters(); // start with a clean slate
      kses_init_filters(); // set up the filters
      }
      }
      } else {
      if ( get_option('comment_registration') || 'private' == $status->post_status )
      wp_die( __('Sorry, you must be logged in to post a comment.') );
      }

      $comment_type = '';

      if ( get_option('require_name_email') && !$user->ID ) {
      if ( 6 > strlen($comment_author_email) || '' == $comment_author )
      wp_die( __('Error: please fill the required fields (name, email).') );
      elseif ( !is_email($comment_author_email))
      wp_die( __('Error: please enter a valid email address.') );
      }

      //ADED BY BUZU

      if(empty($comment_org)){
      wp_die(__('Error: Org is required'));
      }

      //END ADDED

      if ( '' == $comment_content )
      wp_die( __('Error: please type a comment.') );

      //ADED By BUZU just this next line.
      $comment_content = $comment_content . '[_extra_org]' . $comment_org . '[/_extra_org]';

      $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;

      $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');

      $comment_id = wp_new_comment( $commentdata );

      $comment = get_comment($comment_id);
      if ( !$user->ID ) {
      $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
      setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
      setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
      setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN);
      }

      $location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
      $location = apply_filters('comment_post_redirect', $location, $comment);

      wp_redirect($location);

      ?>


      Again, I have commented where I added or modified the php code.

      That does it for me. I have now a custom field. Please note that the technique I'm using here is just a bit too strict and it can certainly be retouched to make it more sophisticated. However, as simple as it is, it works just fine.

      I hope this helps you.

    • 03/29/10 4:39am

      Dave Smith says:

      Hi Buzu B, thanks for this. before I try it, is there any way of achieving the result without editing part of the wordpress core code directly (ie via functions.php)?

      I'm doing this work on a client project, and they will be updating wordpress on a regular basis... I'm keen to ensure they can do updates without breaking the functionality...

This question has expired.





Current status of this question: Completed