• Hello,

    I am currently working on a local server.

    I need to create a callback function as described here to format the comments.

    It is quite simple to do as you only have to cut and paste the code in each file (functions.php + comments.php) and to give the same name to the callback function.

    But i can’t have it running.
    Once i modified the files, i get a blank page. I need to upload again my theme to have it running.

    Thanks for your help,

Viewing 9 replies - 1 through 9 (of 9 total)
  • Sounds like you have an error in your callback function.

    Thread Starter verticalimit

    (@verticalimit)

    How can it be if i only copy and paste the codex code?

    Thread Starter verticalimit

    (@verticalimit)

    Ok I found my mistake.
    Just forgot to put <?php

    Next one:
    My theme is coded with:
    wp_list_comments('avatar_size='.$avsize);

    I want to keep it as i would prefer to remain with the original avatar settings instead of doing it with the callback function.

    I need to add this line to call the callback function:
    <?php wp_list_comments('callback=mytheme_comment'); ?>

    How can i add those two lines together please? only one <?php wp_list_comments()

    Try <?php wp_list_comments('avatar_size='.$avsize . '&callback=mytheme_comment'); ?>

    Thread Starter verticalimit

    (@verticalimit)

    Thanks Esmi. It worked fine.
    But still there is sthg wrong.
    The header and the footer changed of colors for example.

    I don’t think it is connected to your code but rather because i added mytheme_comment function in the theme.

    Here are the changes i have made so far:

    1. functions.php

    I added this code at the end of the file:

    <?php
    function im_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
       <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,$size='48',$default='<path_to_url>' ); ?>
    		 <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
    	  </div>
    	  <?php if ($comment->comment_approved == '0') : ?>
    		 <em><?php _e('Your comment is awaiting moderation.') ?></em>
    		 <br />
    	  <?php endif; ?>
    	  <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
    	  <?php comment_text() ?>
    	  <div class="reply">
    		 <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    	  </div>
    	 </div>
    <?php
    		}
    ?>

    2.comments.php

    I replaced the following line:
    wp_list_comments('avatar_size='.$avsize);

    with:
    wp_list_comments('avatar_size='.$avsize.'&callback=im_comment');

    How can i avoid to loose the original configuration of my theme that i have made through the admin panel?

    Thanks,

    I don’t see how a comment callback function would affect you header and footer styling unless you inadvertently:

    – removed something from functions.php when you added your callback

    – or introduced a validation error into your pages.

    Have you tried validating your pages and correcting any markup errors?

    Thread Starter verticalimit

    (@verticalimit)

    Thanks for your help.
    How can you validate pages when your work on a local server pls?

    If you use Firefox, the Web Developer Toolbar add-on allows you to submit local pages to the online validator. There’s also an HTML Validator add-on that parses pages on the fly – even local ones.

    Other than that, you could copy your page’s output and use the direct input option in the W3C Validator.

    Thread Starter verticalimit

    (@verticalimit)

    I found out that if i was including the callback function within <?php … ?> like this :

    <?php
    ....
    function mytheme_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
       <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,$size='48',$default='<path_to_url>' ); ?>
    
             <?php printf(__('<cite class="fn">%s</cite> <span class="says">dit:</span>'), get_comment_author_link()) ?>
          </div>
          <?php if ($comment->comment_approved == '0') : ?>
             <em><?php _e('Your comment is awaiting moderation.') ?></em>
             <br />
          <?php endif; ?>
    
          <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
    
          <?php comment_text() ?>
    
          <div class="reply">
             <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
          </div>
         </div>
    <?php
            }
    ?>

    it was working better than adding at the end the following code:

    <?php
    function im_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
       <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,$size='48',$default='<path_to_url>' ); ?>
             <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
          </div>
          <?php if ($comment->comment_approved == '0') : ?>
             <em><?php _e('Your comment is awaiting moderation.') ?></em>
             <br />
          <?php endif; ?>
          <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
          <?php comment_text() ?>
          <div class="reply">
             <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
          </div>
         </div>
    <?php
            }
    ?>

    To call the function, i used:
    wp_list_comments('avatar_size='.$avsize.'&callback=im_comment');

    and after:
    wp_list_comments('avatar_size='.$avsize.'type=comment&callback=im_comment');

    As a result, the theme and its parameters are remaining but the comments are not showing.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘wp_list_comments()’ is closed to new replies.