WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add a comment field (81 posts)

  1. sicktb
    Member
    Posted 10 months ago #

    Dear all,

    Im trying to ad a custom comment field that works the same as the "Message" field. I found all topics and tutorials. But my php skills are not realy updated.

    What did i add? I put 'test'. This is how i now tryed to edit the comment-template.php

    add_filter('comment_form_default_fields','add_comment_fields');
    
    function comment_form( $args = array(), $post_id = null ) {
    	if ( null === $post_id )
    		$post_id = get_the_ID();
    	else
    		$id = $post_id;
    
    	$commenter = wp_get_current_commenter();
    	$user = wp_get_current_user();
    	$user_identity = $user->exists() ? $user->display_name : '';
    
    	if ( ! isset( $args['format'] ) )
    		$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
    
    	$req      = get_option( 'require_name_email' );
    	$aria_req = ( $req ? " aria-required='true'" : '' );
    	$html5    = 'html5' === $args['format'];
    	$fields   =  array(
    		'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    		            '<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' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
    		            '<input id="email" name="email" ' . ( $html5 ? 'type="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" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
    	);
    
    	$required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
    	$defaults = array(
    		'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
    		'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
    		'test'			=> '<p class="comment-form-comment"><label for="test">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="test" cols="45" rows="8" aria-required="true"></textarea></p>',
    		'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
    		'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
    		'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
    		'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
    		'id_form'              => 'commentform',
    		'id_submit'            => 'submit',
    		'title_reply'          => __( 'Leave a Reply' ),
    		'title_reply_to'       => __( 'Leave a Reply to %s' ),
    		'cancel_reply_link'    => __( 'Cancel reply' ),
    		'label_submit'         => __( 'Post Comment' ),
    		'format'               => 'xhtml',
    	);

    And here i edit the 'test' in the comments.php from the theme

    <?php $comment_args = array( 'title_reply'=>'Got Something To Say:',
    
    'fields' => apply_filters( 'comment_form_default_fields', array(
    
    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Your Good Name' ) . '</label> ' . ( $req ? '<span>*</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">' . __( 'Your Email Please' ) . '</label> ' .
    
                    ( $req ? '<span>*</span>' : '' ) .
    
                    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />'.'</p>',
    
        'url'    => '' ) ),
    
        'comment_field' => '<p>' .
    
                    '<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label>' .
    
                    '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
    
                    '</p>',
    
        'comment_notes_after' => '',
    
            'test' => '<p>' .
    
                    '<label for="test">' . __( 'Hoe maak je kaas?:' ) . '</label>' .
    
                    '<textarea id="test" name="test" cols="45" rows="8" aria-required="true"></textarea>' .
    
                    '</p>',
    
        'comment_notes_after' => '',
    
    );
    
    comment_form($comment_args); ?>
  2. sicktb
    Member
    Posted 10 months ago #

    Some more information.

    I replaced the code
    <?php comment_form(); ?>

    With the code:

    <?php $comment_args = array( 'title_reply'=>'Got Something To Say:',
    
    'fields' => apply_filters( 'comment_form_default_fields', array(
    
    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Your Good Name' ) . '</label> ' . ( $req ? '<span>*</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">' . __( 'Your Email Please' ) . '</label> ' .
    
                    ( $req ? '<span>*</span>' : '' ) .
    
                    '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />'.'</p>',
    
        'url'    => '' ) ),
    
        'comment_field' => '<p>' .
    
                    '<label for="comment">' . __( 'Let us know what you have to say:' ) . '</label>' .
    
                    '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>' .
    
                    '</p>',
    
        'comment_notes_after' => '',
    
            'test' => '<p>' .
    
                    '<label for="test">' . __( 'Hoe maak je kaas?:' ) . '</label>' .
    
                    '<textarea id="test" name="test" cols="45" rows="8" aria-required="true"></textarea>' .
    
                    '</p>',
    
        'comment_notes_after' => '',
    
    );
    
    comment_form($comment_args); ?>

    Why? I need to make different comments-forms on all pages.

    With kind regards,
    Taro

  3. sicktb
    Member
    Posted 10 months ago #

    http://blog.ideashower.com/post/15147134893/wordpress-plugin-extra-comment-fields

    This maybe helps me but i think its not up to date...

    [Moderator Note: Please ensure that you are embedding links correctly in your posts.]

  4. bcworkz
    Member
    Posted 10 months ago #

    Please do not alter your core installation files, you will sooner or later regret this choice. In this case it is not required, there are clean ways to alter the comment form.

    You can alter your theme files if you like, but if it is a maintained theme with updates, you should create a child theme to protect your changes.

    To alter the comment form (or hack WP in general), you hook into a filter or action to alter how things work.

    To alter the default form, hook the 'comment_form_defaults' filter and alter the definition array passed to your callback. There are also filters for each individual default field if that works better for you.

    To add additional fields, you could add them to the defaults as mentioned above, or hook the 'comment_form' action and echo out whatever HTML you want to appear at the bottom of the form. This will appear after the submit button but still inside the form.

    The code for this can be added to your child theme functions.php, or you could create a simple custom plugin to contain the code.

  5. sicktb
    Member
    Posted 10 months ago #

    Ok so i should not edit the comment-template.php

    Meaning i can only edit the comments.php and function.php

    <?php comment_form(); ?> <- this code should be removed and replaced by the code i pased. Above in my 2nd post. But as you told me bcworkz. I can add additional fields useing the defaults. But what if i need to ad like 10 more fields? I need to add more array's somehow with out addign the core files.

    Is this done in the function.php? And if so.. how? ;)

  6. sicktb
    Member
    Posted 10 months ago #

    I think i found it with the following plugin: http://blog.ideashower.com/post/15147134893/wordpress-plugin-extra-comment-fields

    But when i get to the part to show the result from the command im a bit lost...The code below is from mij comment.php i did ad the code:
    test?: <?php print $comment->extra_test; ?>

    <?php
    /**
     * The template for displaying Comments.
     *
     * The area of the page that contains both current comments
     * and the comment form. The actual display of comments is
     * handled by a callback to twentyten_comment which is
     * located in the functions.php file.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    ?>
    
    			<div id="comments">
    <?php if ( post_password_required() ) : ?>
    				<p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'twentyten' ); ?></p>
    			</div><!-- #comments -->
    <?php
    		/* Stop the rest of comments.php from being processed,
    		 * but don't kill the script entirely -- we still have
    		 * to fully load the template.
    		 */
    		return;
    	endif;
    ?>
    
    <?php
    	// You can start editing here -- including this comment!
    ?>
    
    <?php if ( have_comments() ) : ?>
    			<h3 id="comments-title"><?php
    			printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ),
    			number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' );
    			?></h3>
    
    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
    			<div class="navigation">
    				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">←</span> Older Comments', 'twentyten' ) ); ?></div>
    				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
    			</div> <!-- .navigation -->
    <?php endif; // check for comment navigation ?>
    
    			<ol class="commentlist">
    				<?php
    					/* Loop through and list the comments. Tell wp_list_comments()
    					 * to use twentyten_comment() to format the comments.
    					 * If you want to overload this in a child theme then you can
    					 * define twentyten_comment() and that will be used instead.
    					 * See twentyten_comment() in twentyten/functions.php for more.
    					 */
    					wp_list_comments( array( 'callback' => 'twentyten_comment' ) );
    				?>
    
    			test?: <?php print $comment->extra_test; ?>
    
    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
    			<div class="navigation">
    				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">←</span> Older Comments', 'twentyten' ) ); ?></div>
    				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>
    			</div><!-- .navigation -->
    <?php endif; // check for comment navigation ?>
    
    	<?php
    	/* If there are no comments and comments are closed, let's leave a little note, shall we?
    	 * But we only want the note on posts and pages that had comments in the first place.
    	 */
    	if ( ! comments_open() && get_comments_number() ) : ?>
    		<p class="nocomments"><?php _e( 'Comments are closed.' , 'twentyten' ); ?></p>
    	<?php endif;  ?>
    
    <?php endif; // end have_comments() ?>
    
    <?php comment_form(); ?>
    <p><input type="text" name="test" id="test" size="22" />
    <label for="url"><small>test</small></label></p>
    
    </div><!-- #comments --></blockquote>
    </a>

    [Moderator Note: Please post code or markup between backticks or use the code button. Or better still - use a pastebin. Your posted code may now have been permanently damaged by the forum's parser.]

  7. sicktb
    Member
    Posted 10 months ago #

    I think i found it with the following plugin: http://blog.ideashower.com/post/15147134893/wordpress-plugin-extra-comment-fields

    But when i get to the part to show the result from the command im a bit lost...The code below is from mij comment.php i did ad the code:
    test?: <?php print $comment->extra_test; ?>

    <?php
    /**
     * The template for displaying Comments.
     *
     * The area of the page that contains both current comments
     * and the comment form. The actual display of comments is
     * handled by a callback to twentyten_comment which is
     * located in the functions.php file.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    ?>
    
    			<div id="comments">
    <?php if ( post_password_required() ) : ?>
    				<p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'twentyten' ); ?></p>
    			</div><!-- #comments -->
    <?php
    		/* Stop the rest of comments.php from being processed,
    		 * but don't kill the script entirely -- we still have
    		 * to fully load the template.
    		 */
    		return;
    	endif;
    ?>
    
    <?php
    	// You can start editing here -- including this comment!
    ?>
    
    <?php if ( have_comments() ) : ?>
    			<h3 id="comments-title"><?php
    			printf( _n( 'One Response to %2$s', '%1$s Responses to %2$s', get_comments_number(), 'twentyten' ),
    			number_format_i18n( get_comments_number() ), '<em>' . get_the_title() . '</em>' );
    			?></h3>
    
    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
    			<div class="navigation">
    				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">&larr;</span> Older Comments', 'twentyten' ) ); ?></div>
    				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
    			</div> <!-- .navigation -->
    <?php endif; // check for comment navigation ?>
    
    			<ol class="commentlist">
    				<?php
    					/* Loop through and list the comments. Tell wp_list_comments()
    					 * to use twentyten_comment() to format the comments.
    					 * If you want to overload this in a child theme then you can
    					 * define twentyten_comment() and that will be used instead.
    					 * See twentyten_comment() in twentyten/functions.php for more.
    					 */
    					wp_list_comments( array( 'callback' => 'twentyten_comment' ) );
    				?>
    
    			test?: <?php print $comment->extra_test; ?>
    
    			</ol>
    
    <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
    			<div class="navigation">
    				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">&larr;</span> Older Comments', 'twentyten' ) ); ?></div>
    				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
    			</div><!-- .navigation -->
    <?php endif; // check for comment navigation ?>
    
    	<?php
    	/* If there are no comments and comments are closed, let's leave a little note, shall we?
    	 * But we only want the note on posts and pages that had comments in the first place.
    	 */
    	if ( ! comments_open() && get_comments_number() ) : ?>
    		<p class="nocomments"><?php _e( 'Comments are closed.' , 'twentyten' ); ?></p>
    	<?php endif;  ?>
    
    <?php endif; // end have_comments() ?>
    
    <?php comment_form(); ?>
    <p><input type="text" name="test" id="test" size="22" />
    <label for="url"><small>test</small></label></p>
    
    </div><!-- #comments -->
  8. bcworkz
    Member
    Posted 10 months ago #

    That plugin has not been maintained in quite sometime, it appears the standard way of adding fields may have changed since then. Following the instructions, the added field values will never be sent to the server since the fields are outside of the <form> tags. The main thing this plugin did was to simplify the saving and retrieving extra field values. If you can figure out how to add fields, you can figure out this part too.

    So we are back to your own custom code. It can indeed reside in your theme's functions.php file. You can add as many fields as you like to the default definition array. Add another key/value pair for each field. Code to add one field looks like this:

    function add_bcw_fields($fields){
    	$fields['test'] = '<input type="text" name="test" id="test" size="22" />';
    	return $fields;
    }
    add_filter( 'comment_form_default_fields', 'add_bcw_fields' );

    Once you've added your fields, you need to put the submitted data somewhere. A good hook to use is 'pre_comment_on_post'. You get the data from $_POST just as you would for any other form. You can put the data anywhere that makes sense, commentmeta is typically used.

    Once the data is saved, you might want to display this data along with the comments. For this you alter the theme's comment walker function, or override it in your child theme by redefining it. The name of the walker function is typically passed to the wp_list_comments() call on comments.php as the 'callback' argument and the walker function itself is usually defined on the functions.php file, though this can vary by theme.

    To output the stored data, grab the data from where ever you stored it and sprintf() it where appropriate in the HTML stream output by the walker function.

  9. sicktb
    Member
    Posted 10 months ago #

    Dear bcworkz,

    Your gonna make me happy! Im almoost there i think...

    This is what i have in my function.php.
    I placed the following codes in 2 places in the function.php to test. But this isnt working:

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

    function add_bcw_fields($fields){
    	$fields['test'] = '<input type="text" name="test" id="test" size="22" />';
    	return $fields;
    }
    add_filter( 'comment_form_default_fields', 'add_bcw_fields' );
    
    function twentyten_comment( $comment, $args, $depth ) {
    	$GLOBALS['comment'] = $comment;
    	switch ( $comment->comment_type ) :
    		case '' :
    	?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    		<div id="comment-<?php comment_ID(); ?>"><?php echo $comment->test; ?>
    
    			<div class="comment-author vcard">
    				<?php echo get_avatar( $comment, 40 ); ?>
    				<?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
    			</div><!-- .comment-author .vcard -->
    			<?php if ( $comment->comment_approved == '0' ) : ?>
    				<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
    				<br />
    			<?php endif; ?>
    
    			<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    				<?php
    					/* translators: 1: date, 2: time */
    					printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
    				?>
    			</div><!-- .comment-meta .commentmetadata -->
    
    			<div class="comment-body"><?php comment_text(); ?><?php print $comment->test; ?></div>
    
    			<div class="reply">
    				<?php /* <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> */ ?>
    			</div><!-- .reply -->
    		</div><!-- #comment-##  -->
    
    	<?php
    			break;
    		case 'pingback'  :
    		case 'trackback' :
    	?>
    	<li class="post pingback">
    		<p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
    	<?php
    			break;
    	endswitch;
    }
    endif;
  10. bcworkz
    Member
    Posted 10 months ago #

    Yes, you are getting closer. But you missed a crucial point. The comment system does not automatically process added fields for you, you must handle them yourself. An honest oversight, sometimes such things are handled for you, such as with the Settings API.

    Thus you cannot expect your added fields to be part of $comment. A $comment->test value does not exist. In fact, as it stands, the value you placed in the test field was never saved. It's your responsibility to do so.

    My suggestion on how to save the field data in my previous post was not the best advice, though it would have worked. On further consideration a better hook is the 'wp_insert_comment' action. This way the data is only inserted if the comment checks out and is actually inserted. Save the data with something like this:

    function bcw_handle_comment($id) {
       if (array_key_exists('test', $_POST))
          update_comment_meta( $id, 'bcw_test', $_POST['test']);
    }
    add_action('wp_insert_comment', 'bcw_handle_comment');

    Finally, to display this data in the comment list, insert the following in the twentyten_comment() function where ever it makes sense:
    <?php echo get_comment_meta( $comment->comment_ID, 'bcw_test', true ); ?>

    Not to make more work for you, but you will see this added field is not visible at all in the backend, much less editable. As it stands, the only way to view the field is to look at the comments page, and to edit by using phpMyAdmin. It is possible to add extra columns to the comments table, though a bit tricky. Though I haven't done so, you can also add a metabox to the edit-comment screen that allows admin editing of the field. If and when you are ready to pursue such enhancements, I'm willing to try and help as needed.

  11. sicktb
    Member
    Posted 10 months ago #

    Though I haven't done so, you can also add a metabox to the edit-comment screen that allows admin editing of the field.

    This would make it all easyer. But my main point now is to get it to work that the customer(client) can see what he/she posted. As a admin i just need to remove the comment when needed.

    Do i still need this in the comment.php?

    <?php comment_form(); ?>
    
    <p><input type="text" name="bcw_test" id="bcw_test" size="22" />
    <label for="url"><small>test</small></label></p>
    
    </div><!-- #comments -->

    Total function.php code now: This will not give me a new comment fiel to type. I can only see the comment field that i placed in the comment.php

    function bcw_handle_comment($id) {
       if (array_key_exists('test', $_POST))
          update_comment_meta( $id, 'bcw_test', $_POST['test']);
    }
    add_action('wp_insert_comment', 'bcw_handle_comment');
    
    function twentyten_comment( $comment, $args, $depth ) {
    	$GLOBALS['comment'] = $comment;
    	switch ( $comment->comment_type ) :
    		case '' :
    	?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    		<div id="comment-<?php comment_ID(); ?>">
    
    			<div class="comment-author vcard">
    				<?php echo get_avatar( $comment, 40 ); ?>
    				<?php printf( __( '%s <span class="says">says:</span>', 'twentyten' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
    			</div><!-- .comment-author .vcard -->
    			<?php if ( $comment->comment_approved == '0' ) : ?>
    				<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyten' ); ?></em>
    				<br />
    			<?php endif; ?>
    
    			<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    				<?php
    					/* translators: 1: date, 2: time */
    					printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
    				?>
    			</div><!-- .comment-meta .commentmetadata -->
    
    			<div class="comment-body"><?php comment_text(); ?></div>
                <?php echo get_comment_meta( $comment->comment_ID, 'bcw_test', true ); ?>
    
    			<div class="reply">
    				<?php /* <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> */ ?>
    			</div><!-- .reply -->
    		</div><!-- #comment-##  -->
    
    	<?php
    			break;
    		case 'pingback'  :
    		case 'trackback' :
    	?>
    	<li class="post pingback">
    		<p><?php _e( 'Pingback:', 'twentyten' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' ); ?></p>
    	<?php
    			break;
    	endswitch;
    }
    endif;
    
    /**
     * Register widgetized areas, including two sidebars and four widget-ready columns in the footer.
     *
     * To override twentyten_widgets_init() in a child theme, remove the action hook and add your own
     * function tied to the init hook.
     *
     * @since Twenty Ten 1.0
     * @uses register_sidebar
     */
    function twentyten_widgets_init() {
    	// Area 1, located at the top of the sidebar.
    	register_sidebar( array(
    		'name' => __( 'Primary Widget Area', 'twentyten' ),
    		'id' => 'primary-widget-area',
    		'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    	// Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'Secondary Widget Area', 'twentyten' ),
    		'id' => 'secondary-widget-area',
    		'description' => __( 'An optional secondary widget area, displays below the primary widget area in your sidebar.', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    	// Area 3, located in the footer. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'First Footer Widget Area', 'twentyten' ),
    		'id' => 'first-footer-widget-area',
    		'description' => __( 'An optional widget area for your site footer.', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    	// Area 4, located in the footer. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'Second Footer Widget Area', 'twentyten' ),
    		'id' => 'second-footer-widget-area',
    		'description' => __( 'An optional widget area for your site footer.', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    	// Area 5, located in the footer. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'Third Footer Widget Area', 'twentyten' ),
    		'id' => 'third-footer-widget-area',
    		'description' => __( 'An optional widget area for your site footer.', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    
    	// Area 6, located in the footer. Empty by default.
    	register_sidebar( array(
    		'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
    		'id' => 'fourth-footer-widget-area',
    		'description' => __( 'An optional widget area for your site footer.', 'twentyten' ),
    		'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    		'after_widget' => '</li>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    }
    /** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
    add_action( 'widgets_init', 'twentyten_widgets_init' );
    
    /**
     * Removes the default styles that are packaged with the Recent Comments widget.
     *
     * To override this in a child theme, remove the filter and optionally add your own
     * function tied to the widgets_init action hook.
     *
     * This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
     * to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
     * but they won't have any effect on the widget in default Twenty Ten styling.
     *
     * @since Twenty Ten 1.0
     */
    function twentyten_remove_recent_comments_style() {
    	add_filter( 'show_recent_comments_widget_style', '__return_false' );
    }
    add_action( 'widgets_init', 'twentyten_remove_recent_comments_style' );
    
    if ( ! function_exists( 'twentyten_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     *
     * @since Twenty Ten 1.0
     */
    function twentyten_posted_on() {
    	printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s', 'twentyten' ),
    		'meta-prep meta-prep-author',
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
    			get_permalink(),
    			esc_attr( get_the_time() ),
    			get_the_date()
    		),
    		sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
    			get_author_posts_url( get_the_author_meta( 'ID' ) ),
    			esc_attr( sprintf( __( 'View all posts by %s', 'twentyten' ), get_the_author() ) ),
    			get_the_author()
    		)
    	);
    }
    endif;
    
    if ( ! function_exists( 'twentyten_posted_in' ) ) :
    /**
     * Prints HTML with meta information for the current post (category, tags and permalink).
     *
     * @since Twenty Ten 1.0
     */
    function twentyten_posted_in() {
    	// Retrieves tag list of current post, separated by commas.
    	$tag_list = get_the_tag_list( '', ', ' );
    	if ( $tag_list ) {
    		$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
    	} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
    		$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
    	} else {
    		$posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyten' );
    	}
    	// Prints the string, replacing the placeholders.
    	printf(
    		$posted_in,
    		get_the_category_list( ', ' ),
    		$tag_list,
    		get_permalink(),
    		the_title_attribute( 'echo=0' )
    	);
    }
    endif;
  12. bcworkz
    Member
    Posted 10 months ago #

    I was pointing out the possibilities for full functionality, it's up to you to decide if it's worth doing or not. Either way, we need to get basic functionality before attacking any non-essential features :)

    Yes, remove the added field code on comment.php. Though you can see the field, it is outside the <form> tags so any input is never sent to the server when the form is submitted.

    Your latest version of the code is missing the add_bcw_fields() code. This is the code that displays the field in the form. (At some point you will want to add labels and other bits to the input field so it fits seamlessly in your form) You need both this and the bcw_handle_comment() code that saves the value to the DB.

    BTW, next time you need to post a big block of code, please use pastebin.com and just provide a link here. Posting large blocks of code (more than a dozen lines) is frowned upon in these forums. Also, the pastebin display has syntax highlighting, making reading many lines of code much easier. For small code snippets though, having the code inline with commentary is less disruptive to read IMO.

  13. sicktb
    Member
    Posted 10 months ago #

    Im not sure how to add that 2 lines of code and where...Maybe like this below?

    function bcw_handle_comment($id) {
    if (array_key_exists('test', $_POST))
    update_comment_meta( $id, 'bcw_test', $_POST['test']);
    }
    add_action('wp_insert_comment', 'bcw_handle_comment');

    //////////

    <div class="comment-body"><?php comment_text(); ?></div>
    <div class="comment-body"><?php add_bcw_fields(); ?></div>
    <div class="comment-body"><?php bcw_handle_comment(); ?></div>
    <?php echo get_comment_meta( $comment->comment_ID, 'bcw_test', true ); ?>

  14. bcworkz
    Member
    Posted 10 months ago #

    Not exactly. The code goes in your theme's functions.php. The rest of the code looks like template code. There are 3 parts to the code I've presented at different points, let's not confuse them, they each do something different, and it matters to some extent where each goes.

    1. echo get_comment_meta( $comment->comment_ID, 'bcw_test', true );
    This goes on any comment template file or function (such as twentyten_comment()) where you want the values stored to be displayed. It must be inside a PHP code block delimited by <?php ?>

    2. bcw_handle_comment(); function definition and it's associated add_action()
    This function stores the entered value in a DB table when a comment is submitted. It can go anywhere on your theme's functions.php file, provided it is inside a PHP code block delimited by <?php ?> and it is not inserted inside another function or class definition.

    3. add_bcw_fields(); function definition and it's associated add_action()
    This function defines the form HTML that displays the field in the comment form. It can go anywhere on your theme's functions.php file, provided it is inside a PHP code block delimited by <?php ?> and it is not inserted inside another function or class definition.

    This means you do not want this code in your last snippet:

    <div class="comment-body"><?php add_bcw_fields(); ?></div>
    <div class="comment-body"><?php bcw_handle_comment(); ?></div>

    These functions do not output anything, there is no point in calling them from a template or comment display function. They only serve to set things up behind the scenes when their related actions fire.

    In summary, based on the functions.php content you posted earlier, just change that so the first part looks like this:

    // Add extra field to comment form
    function add_bcw_fields($fields){
       $fields['test'] = '<input type="text" name="test" id="test" size="22" />';
       return $fields;
    }
    add_filter( 'comment_form_default_fields', 'add_bcw_fields' );
    //Save the extra comment field value
    function bcw_handle_comment($id) {
       if (array_key_exists('test', $_POST))
          update_comment_meta( $id, 'bcw_test', $_POST['test']);
    }
    add_action('wp_insert_comment', 'bcw_handle_comment');
    //Override default theme function to display a comment
    function twentyten_comment( $comment, $args, $depth ) {
       // Code continues...

    You are possibly thinking now "What's with all the explanations? Just show me how to get this thing working!" I'm hoping you can begin to understand what each bit of code does and how it fits into the overall comment process, which in turn partly determines where each code goes and where it doesn't.

    The functions called when an action fires can go almost anywhere because their execution only happens when the action actually happens. The code that displays the stored value has to go at a particular spot so the data ends up being displayed in the right place.

    I hope that this finally gets a basic field working so you can start working on some real fields. I hope it all sort of makes sense to you so you can work through the next phase without any perplexing errors. (Errors are inevitable, the difference being if you can resolve them on your own or not). Good luck.

  15. sicktb
    Member
    Posted 10 months ago #

    I think it must be working. But the problem that the field is not showing is because im logged in? The website can only be shown when logged in. So i need to place the correct code... in the correct posistion or edit a line for this field?

    And dont i need to edit this:
    update_comment_meta( $id, 'bcw_test', $_POST['test']);
    to:
    update_comment_meta( $id, 'test', $_POST['test']);

    http://pastebin.com/embed_js.php?i=LJ7T8gCe"

  16. bcworkz
    Member
    Posted 10 months ago #

    test vs. bcw_test
    You could store the value under 'test' if you like. Just be sure to coordinate with the call to get_comment_meta(), the key used in each must match. I would encourage you to never use plain language words for variable, function, array key and similar PHP names. The risk of name collisions with other plugins increases when this is done. It's good practice to preface all names with some unique sequence of letters to avoid this.

    I preface all such names in my custom plugin "bcworkz" (it contains many of my WP hacks) with the string 'bcw_', the first 3 letters of my plugin name. The snippets I provided came from that plugin. I encourage you to adopt a similar scheme.

    FYI, the input field name does not need to match the metadata key used to store the value, though if it did it might be less confusing. As long as you can keep the different names straight and the code works and the variants are properly coordinated, you can do whatever makes sense to you. I changed my code as little as necessary to illustrate using your test input field instead of my original field, at the same time showing good practice by altering name words used in the DB to avoid name collisions.

    Fields for Logged In Users
    If these fields are only for logged in users, we need to change things up some because the added default fields are never displayed for logged in users. Please replace the current function add_bcw_fields() and the associated add_filter() call with this version:

    // Add extra field to comment form
    function add_bcw_fields(){
       echo '<input type="text" name="test" id="test" size="22" />';
    }
    add_action( 'comment_form_logged_in_after', 'add_bcw_fields' );

    Note that we are now hooking an action instead of a filter, so we echo content instead of returning it. Sorry for any confusion, I simply made a bad assumption about how the fields were to be used.

  17. sicktb
    Member
    Posted 10 months ago #

    Thx bcworkz that works like a charm.

    I tryed to customize some information but i think i need some facts if you can tell me. I hope the below is posibble in some way.

    I need to do the following exemple:

    1) Make: 10 logins(customers)
    2) Make: 6 pages a person (totaal 60 pages)
    3) Make: custom fields for this 6 pages

    I was thinking to do this my makeing this custom fields in the function.php and put the correct fields in a comment.php. This way i simple need to make 6x a diffrent comment.php. And include the correct comment.php this will replace the <?php comments_template(); ?>.

    Seems this isnt realy how it works. I can place the code from the function to the comment.php. This way i can edit it on the normal comment.php just like in the function.php. The error will come when i try to add <?php include 'comment.php'; ?>.

    Code function.php now:
    Code comment.php now: http://pastebin.com/raw.php?i=j4Gnbwm2

  18. bcworkz
    Member
    Posted 10 months ago #

    If I understand correctly, each customer's comment section on their pages have unique custom fields in the comment form, and the values saved from those fields are displayed in some unique way for each customer.

    You can cause different comment templates to be loaded by using the 'comments_template' filter and returning the path to the correct template. And you could simply put a custom form on the template instead of calling comment_form(). Which negates the need to hook into comment form actions that I suggested previously.

    My instinct tells me this is not a good approach though. I would try storing whatever is different from customer to customer in user meta under a common key name. Then your single comment template can get that unique content by getting it out of user meta using the same key each time. No need to generate multiple variations of the template and manage which one gets loaded for which user.

    Even if that doesn't work because I don't understand what's unique, I believe there must be a way to do this without generating multiple templates.

  19. sicktb
    Member
    Posted 10 months ago #

    Ill try to explain it beter. Cus i dont realy understand how this "user meta" is working.

    Totaal 10(will be more) users that can login to the website with his own login information.

    They will only see a standaard menu. This menu will be the same for all the user that will login. Cuz im gonna try to put all the pages on 1 layout and use the scroll function Go to page one. This will be linked on the custom title of that page.

    At the backand i have to create 6 pages per person. However all these pages will have the same template. This way all the comment field will be the same for every user and the menu will always work. I only have to set (with a plugin) that those 6 pages can be shown by a specific user. This way thy will not see all the other 6x pages that are on the website.

    But if im correct im gonna get a problem with the <?php echo get_comment_meta( $comment->comment_ID, 'bcw_test', true ); ?>

    If user1 posts a comment on his page than user2 will see this comment ?

    To change the comment_form or poiting out the following?: Comments_template_Filter

  20. bcworkz
    Member
    Posted 10 months ago #

    Thanks for that, I see now I'm confusing template pages (the PHP page/file) with WP pages (the post type "Page"). I'm sure there will not be a problem with inappropriate visibility on the front end. Comment meta is related to a specific comment, the value stored is only retrieved when a particular comment is being displayed. In turn, a particular comment is only displayed if it is associated with a particular post. By inheritance, the meta value is only used when the grandparent post is being displayed.

    Yes you can filter the comment template being loaded, but I still don't think it's necessary. Any unique content can be stored in the DB and only displayed to users that have the right to see it. You know your situation far better than me, I still may not be getting it. If your scheme works, then it's all good. But I hope to save you needless work and make your system efficient. OTOH, following an approach you do not understand can be more trouble than it's worth.

    On the backend, I'm not so sure about inappropriate visibility. This applies not only to comment meta, but comments themselves. (Unless you code some provision, comment meta is not visible on the backend anyway) If the user has permission to view the comments screen, they will see all comments in the system, not just theirs... I think. I've no experience with segregating access to comments.

    You should be able to test this now with the test field. Add a comment as user1 to user1's page. Login as user2 and see what you can see. Since you can't see user1's post, you can't see the comment nor the test field. But can you see user1 comments on the backend? Or can you not see any comments? Only user2 comments? I'm not sure, so test!

    On a related note, you could probably hook into the add new user process and if adding a particular role, automatically create 6 pages for the user. You could even add a metabox to the add new user screen where you could enter the titles for each page or any other data that is unique and cannot be scripted. Not sure exactly what's involved, but it should be possible.

  21. sicktb
    Member
    Posted 9 months ago #

    I got it almoost to working. I can now add custom fields to the reply field in a comment.php and this way i can make custom templates that i can load for specific pages.

    But i have the add field function in the function.php this adds the field below the reply. If i whant to put this on every comment.php it will give me a error.

    This: comment.php is what i have for a comment.php that will show the correct field in the correct places.

    And this code: function.php is still located in the function.php that makes the field and places it in the comment place.

    I have to get this code from function.php and place it in the comment.php whit out getting errors...

    Putting the code <?php echo get_comment_meta( $comment->comment_ID, 'bcw_test', true ); ?> in the comment.php works... But that only works for the first post. If i want to post a new comment the line will disapear and will only be show in the new comment.

  22. bcworkz
    Member
    Posted 9 months ago #

    I may be misunderstanding what you're really trying to do.

    First, the echo get_comment_meta() line that displays the value. You say it's in the correct place on comment.php. But it only shows once after the comments are listed, with the content related to the last comment. In order for it to show the stored value related to each comment, this line must be within your child theme's twentyten_comment() function on functions.php. Right where you have it commented out.

    Why was this commented out version not working for you?

    And now the add_bcw_fields() function. There is no need to place it on comments.php, because it runs as an action callback. Callbacks run at a particular time in the page request process no matter where the code appears in the file. But you certainly cannot have it in more than one place because it throws an error as you have seen.

    Since where it is on functions.php places the input field below the reply box in every case, why would you want to put it on comment.php? Where else would you want it to appear?

    I am going on the assumption that this added field is presented to all logged in commenters as part of the comment/reply form. Whatever is input is related to that one comment. Any value entered for another comment will be related only to that other comment.

    Thus, when the comments are listed, the value stored is to be displayed along with it's related comment. Once this value and comment are submitted, there is no possibility of editing this field or the comment, except by admins in the backend.

    Is there anything in my assumption that is not correct?

  23. sicktb
    Member
    Posted 9 months ago #

    "Is there anything in my assumption that is not correct?"
    I think its the following:

    "Why was this commented out version not working for you?"

    It works good for me...But i still need 6 diffrent pages. Atm i can add fields to the standaard comment that will be the same for every page that you will make on the website. So i thougt i needed to remove the <?php echo get_comment_meta( $comment->comment_ID, 'bcw_test', true ); ?> from the function.php. But i think this can be in the function.php but i still need to change the input fields display. See below.

    But in my case i need to have like 6 diffrent comment forms.

    Like the following

    Page1
    Do you like cheese?:
    /////input field/////

    Do you like candy?:
    /////input field/////

    (Submit button)

    Page2
    Do you like flowers?:
    /////input field/////

    Do you like cats or dogs?:
    /////input field/////

    (Submit button)

  24. bcworkz
    Member
    Posted 9 months ago #

    You have a design choice to make here. The default comments.php uses calls to wp_list_comments() and comment_form(). If you still make these calls, you can change comment.php all you want and not get the desired results. My proposals focused on altering these calls, but such changes apply to all calls.

    At least wp_list_comments() takes arguments so it can generate different content based on which call back is specified. You will then need 6 different versions of 'twentyten_comment()' (with different names) to go with your 6 different comment templates.

    Or you could simply put the loop code and content directly on comments.php and not make a call to wp_list_comments() at all. comment_form() has no such argument possibility. You really do need to put the form code directly on comments.php.

    There are alternatives. You can leave comments.php as it is and make twentyten_comment() and the added form fields responsive to some condition that decides what content to present. For instance, say the content required is based on some custom capability, you could do something like this:

    if( current_user_can('like_cheese')) echo 'Favorite cheese? <input type="text" name="test" id="test" size="22" />'
    else if( current_user_can('like_flowers')) echo 'Favorite flower? <input type="text" name="test" id="test" size="22" />'
    else echo 'What do you like? <input type="text" name="test" id="test" size="22" />'

    and something similar for displaying the input values with each comment. Of course it does not have to be capabilities, it could be based on a user meta value, or the label could even be the user meta, ssuch that every user has their own custom label. There really is no need for 6 different templates, though you can do that as well.

    Or you could dynamically include a code page that only has the content that's different for whatever capability or condition you're altering the labels for, a sort of sub-template. All common code remains on comments.php.

    There's likely other possibilities that aren't occurring to me. The main thing is where does the code decide to do something different? It should be as late as possible so as much common code as possible is all in one place and what varies is kept to a minimum. You don't want to find you need to change the same code some time in the future 6 times when once would have sufficed. Put aside your pre-conception of multiple comment pages and look at the problem creatively. There's possibly a good approach that's not obvious.

  25. sicktb
    Member
    Posted 9 months ago #

    If i'm correct i can use the code on the following way in the comment.php.

    http://pastebin.com/raw.php?i=ZiqrfCz2

    Why do i want templates?: I can easly copy the 6 pages with the correct template selected on it in WordPress with a plugin.

    And im not sure how you whant me to change it to a dynamically include page...(<?php include 'page1code.php'; ?>)? And put the same code there ?

  26. bcworkz
    Member
    Posted 9 months ago #

    Yes, your latest code snippet can work if the input field is showing up where you want it. (and you are really controlling output by capability. I also noticed I forgot a terminating ; after each line)

    If you feel having different templates will work best for you in terms of maintaining your site, then by all means do it that way. I tend to look for the most efficient approach even when doing so would make little difference. Having nearly identical code in multiple places simply violates my sense of order. But if multiple templates work for you and you understand how it all works and you have no issue maintaining such an arrangement, then that is what you should do.

    In that case, abandon the calls to wp_list_comments() and comment_form() and twentyten_comment() and my proposed hooks. Place the related function code directly on each template, altering fields and labels as needed.

    The dynamic include page was just an idea, the include statements would need to be placed in a conditional structure much like the echo input fields were in my last example. Something like this:

    <?php if( current_user_can('like_cheese')) include 'page1code.php';
    else if( current_user_can('like_flowers')) include 'page2code.php';
    else include 'pagedefaultcode.php'; ?>

    It's the same logic you would be using to decide which template to load. Instead of choosing between 6 full templates, you choose between only the portions that actually change. Depending on what that is, some reorganization may be required. This code would go on the comments.php page where ever the included code would normally be inserted if all code were in one big file.

    I've given you a lot of different ideas, I hope it's not too confusing. Many of these ideas only work for a certain approach. You should now decide which approach you wish to use. I will then stop with the ideas and focus on helping you get your chosen approach working.

  27. sicktb
    Member
    Posted 9 months ago #

    I Think multiple templates is the best way for me. It can easily be changed bij admin per page in the wordpress back.

    Im still using your bcw_ so i changed the following code:

    if( current_user_can('like_cheese')) echo 'Favorite cheese? <input type="text" name="bcw_test" id="bcw_test" size="22" />';
    else if( current_user_can('like_flowers')) echo 'Favorite flower? <input type="text" name="bcw_test" id="bcw_test" size="22" />';
    else echo 'What do you like? <input type="text" name="bcw_test" id="bcw_test" size="22" />';

    But when i put this to the comment.php it gives me a total of 3 fields now. One is the standaard comment_input. One is the get_comment_meta located in the function. And the last is this new comment input "What do you like?". When i put something in all the 3 fields it gives me only the result from the normal comment_input and the bcw_test located in function.php.

    I need to remove the one from function and the standaard comment box. To remove the one from function i need to remove this code?:

    // Add extra field to comment form
    function add_bcw_fields(){
    echo '<input type="text" name="test" id="test" size="22" />';
    }
    add_action( 'comment_form_logged_in_after', 'add_bcw_fields' );

    But how to disable the normal comment?

  28. bcworkz
    Member
    Posted 9 months ago #

    You will probably throw up your arms is disgust with my next proposal and scream "What a waste of time!"

    We need to start over from the beginning :( well, sort of.
    It's entirely my fault. First I was trying to work with the WP way of handling comments, then I was on a mission to make your code efficient, all the while probably confusing you to no end. All I can do now is offer a sincere apology. I feel badly, I can only hope that you at least learned something? I don't blame you if you do not want to deal with me any more.

    If you're still with me, you are a saint with your boundless patience. We do not need the add_bcw_fields() function. We still need the bcw_handle_comment($id) function on functions.php. We will need to move the modified twentyten_comments() function. Start with an unmodified copy of the twentyten comments.php file. We will make a custom comments template that contains all the boilerplate which you can then copy 6 times and alter the specifics for each version.

    Insert the modified twentyten_comments() function definition either at the top under the template header or at the bottom after everything, which ever fits your coding style. Be sure it's contained in a <?php ?> block. Give it a different function name. Also place the new name in the line wp_list_comments( array( 'callback' => 'twentyten_comment' ) );

    Replace the comment_form() line near the bottom with the following distilled down version of the function definition (untested):

    <?php if ( comments_open( $post_id ) ) : ?>
    	<div id="respond" class="comment-respond">
    		<h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
    		<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
    			<?php echo $args['must_log_in']; ?>
    		<?php else : ?>
    			<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
    				<?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
    				<input type="text" name="test" id="test" size="22" />
    				<?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
    				<p class="form-submit">
    					<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
    					<?php comment_id_fields( $post_id ); ?>
    				</p>
    			</form>
    		<?php endif; ?>
    	</div><!-- #respond -->
    <?php else :
    	do_action( 'comment_form_comments_closed' );
    endif; ?>

    Test what you have so far, if all good, expand the test input field to the fields you actually need. The three places to alter the code for the actual fields is the above form code, the modified twentyten_comments() output function, and the bcw_handle_comment($id) save values function. Be sure the field names are coordinated between the three locations. Test again. Tweak the HTML and CSS until it is exactly what you want.

    Once you are happy with the boilerplate, you can copy it multiple times and alter the content for each as needed, and implement the template switching code. While there will be bugs to iron out, this should get you very close to what you want.

  29. sicktb
    Member
    Posted 9 months ago #

    "I don't blame you if you do not want to deal with me any more."

    Dont worry man. I'm really happy that your helping me at all. Ill gonna have the code above a try. With all the information that you give me i have been looking for some alts myself. And i like to have your opinion about the plugins. And if i can use this. Cus i maybe still want the option to edit the comments in the back of wordpress.

    1) custom-metadata
    2) easy-custom-fields
    3) Custom-Metaboxes-and-Fields-for-WordPress

    I have been looking at this plugins and tryed some. But its all magic for me on how to get it to work. And i mis the information to know if this can be used in my case.

  30. bcworkz
    Member
    Posted 9 months ago #

    I'm glad you're still happy, thanks for hanging in there.

    I've no experience with any of those, but on a cursory look, here's my thoughts.

    Custom-Metadata
    I'm unsure if it can handle 6 different variations of comment forms.

    Easy-Custom-Fields
    This does not appear to support comments, only post types.

    Custom-Metaboxes-and-Fields-for-WordPress
    This does not appear to support comments, only post types. The comment page does not natively support metaboxes. Metaboxes are not necessarily related to metadata, they allow arbitrary HTML to be contained in a draggable container. This is not a plugin, it is theme extension. A bit unorthodox, but it does offer some interesting features, but not for comments.

    So custom-metadata is the only viable candidate. I haven't installed it, but it's not clear how it might handle 6 different comment forms.

    I just had another thought, please confirm. I'm assuming (gotta stop doing that) when a user likes cheese, all the comments on the page he is viewing is about cheese, there are no comments about flowers, and so on for each kind of "like". If the comment page needs to display various likes, not just cheese likes, things get more complicated and the entire scheme may need adjustment.

Reply »

You must log in to post.

About this Topic