WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to get WordPress TwentyTwelve comments.php to work on another theme? (2 posts)

  1. skwayred
    Member
    Posted 1 year ago #

    Currently, I'm using a WordPress theme that is built on Foundation. However, the theme doesn't have its own comments.php file and it's currently using the soon to be deprecated comments.php from wordpress\wp-includes\theme-compat folder.

    So what I did is to copy/paste the latest comments.php file from the TwentyTwelve theme folder into my current theme folder. However, this results in an error:

    Warning: call_user_func() expects parameter 1 to be a valid callback, function 'twentytwelve_comment' not found or invalid function name in C:\xampp\htdocs\wordpress\wp-includes\comment-template.php on line 1334

    What do I need to change in the TwentyTwelve comments.php file to get it to work on the current theme?

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/wp_list_comments

    remove the callback code from the wp_list_comments() code in comments.php:

    change this line:

    <?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>

    to:

    <?php wp_list_comments( array( 'style' => 'ol' ) ); ?>

    or alternatively, also copy the function twentytwelve_comment() from Twenty Twelve's functions.php, and add it into your theme's functions.php; code below:

    /**
     * Template for comments and pingbacks.
     *
     * To override this walker in a child theme without modifying the comments template
     * simply create your own twentytwelve_comment(), and that function will be used instead.
     *
     * Used as a callback by wp_list_comments() for displaying the comments.
     *
     * @since Twenty Twelve 1.0
     */
    function twentytwelve_comment( $comment, $args, $depth ) {
    	$GLOBALS['comment'] = $comment;
    	switch ( $comment->comment_type ) :
    		case 'pingback' :
    		case 'trackback' :
    		// Display trackbacks differently than normal comments.
    	?>
    	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
    		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
    	<?php
    			break;
    		default :
    		// Proceed with normal comments.
    		global $post;
    	?>
    	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    		<article id="comment-<?php comment_ID(); ?>" class="comment">
    			<header class="comment-meta comment-author vcard">
    				<?php
    					echo get_avatar( $comment, 44 );
    					printf( '<cite class="fn">%1$s %2$s</cite>',
    						get_comment_author_link(),
    						// If current post author is also comment author, make it known visually.
    						( $comment->user_id === $post->post_author ) ? '<span> ' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
    					);
    					printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
    						esc_url( get_comment_link( $comment->comment_ID ) ),
    						get_comment_time( 'c' ),
    						/* translators: 1: date, 2: time */
    						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
    					);
    				?>
    			</header><!-- .comment-meta -->
    
    			<?php if ( '0' == $comment->comment_approved ) : ?>
    				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
    			<?php endif; ?>
    
    			<section class="comment-content comment">
    				<?php comment_text(); ?>
    				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
    			</section><!-- .comment-content -->
    
    			<div class="reply">
    				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    			</div><!-- .reply -->
    		</article><!-- #comment-## -->
    	<?php
    		break;
    	endswitch; // end comment_type check
    }

Topic Closed

This topic has been closed to new replies.

About this Topic