WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom comments.php few issues (5 posts)

  1. Jesse Friedman
    Member
    Posted 3 years ago #

    I have created a totally custom commenting template page. Everything was working fine until we decided to add threading to posts. I obviously started in my discussion settings and turned threading on.

    From there I went to my comments.php code seen below (a snippet from inside the comments foreach loop)

    <div class="review hreview">
    
       <h3 class="review"><?php global $title; echo $title; ?> Review by <span class="reviewer"><?php comment_author_link() ?></span>, <span class="dtreviewed"><?php comment_date('F j, Y') ?></span></h3>
    
       <!-- start call for custom function ratings system -->
       <?php comment_ratings_list(); ?>
    
       <?php if (function_exists('get_average_comment_rating')) { ?> <span class="rating" style="display: none"><?php echo round(get_average_comment_rating(),1); ?></span> <?php } ?>
    
       <!-- end call for custom function ratings system -->		
    
       <span class="summary"><?php comment_text() ?></span>
    
    </div>

    Now what I'd like to do is add a special class to this <div class="review hreview"> div if it's a threaded comment so I can indent it.

    Second I'd like to add a reply button which I thought would be simple enough.

    I added

    comment_reply_link(array_merge( $args, array('reply_text' => 'Reply', 'add_below' =>
     $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'])));

    but I get an error saying that the first argument in the array_merge function isn't an array. I haven't declare $args anywhere and I'm not sure what it's value should be. I tried calling it with no arguments but I get nothing at all instead of an error.

    I can't use wp_list_comments because I need to insert the custom function calls and I don't want to have to rewrite all the css for the comments.

    Please Help!

  2. Doodlebee
    Member
    Posted 3 years ago #

    Hi Jesse! I saw your "call for help" on Twitter, so I'm going to give it a go. A warning: I didn't get much sleep last night, so I might have jibberish - so please bear with me, and forgive any weirdness :)

    Okay so what I gather is you want a custom layout for your comments, with comment replies. It would help to see your comments_rating_list() (and our get_average_comment_rating())function - is that a plugin? From what I see here, there isn't a whole lot that's wrong, but without actually seeing the functions (to check for conflicts/errors), there's not much to go by.

  3. Doodlebee
    Member
    Posted 3 years ago #

    ..and actually, you *can* use wp-list_comments, if that helps. You can use a function to rewrite how it's output. Here's an example I use all the time (I separate my stuff for easier management, but you don't have to):

    single.php

    <div id="comments_div">
             <?php include(TEMPLATEPATH . '/commentform.php');
                   comments_template(); ?>
           <!--/comments_div-->
           </div>

    commentform.php holds the "form" layout. the comments_template() (which is basically comments.php) looks like so:

    <?php // Do not delete these lines
    	  if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    		die ('Please do not load this page directly. Thanks!');
    
    	if ( post_password_required() ) {
    		 // message for notifying of password-protected posts
    		return;
    	}
    ?>
    
    <?php if (have_comments()) : ?>
        <h3 class="hot_topics">Add a Comment</h3>
        <div id="commentlist">
    	<?php wp_list_comments('type=comment&callback=format_comment&style=div'); ?>
    	<!--/commentlist-->
    	</div>
    
    	<div class="navigation">
    		<div class="alignleft"><?php previous_comments_link() ?></div>
    		<div class="alignright"><?php next_comments_link() ?></div>
    	</div>
    
    	<?php $postinfo = get_post($post->ID);
    	      if(comments_open()) : ?>
    		  <a class="comment-reply-link" href="#goto">Would you like to join the discussion?</a>
    
    	<?php else : ?>
    	      <small>Sorry - comments are closed on this subject. You can thank the spammers for that one.</small>
    	<?php endif;
    	      endif; ?>

    You'll see at the top I'm using wp_list_comments, but I'm pulling in a callback function to mess with the layout and add classes as I see fit. This section of my functions.php file looks like so:

    function list_pings($comment, $args, $depth) {
           $GLOBALS['comment'] = $comment;
    ?>
            <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
    <?php }
    
    add_filter('get_comments_number', 'comment_count', 0);
    function comment_count( $count ) {
    	global $id;
    	$get_comments= get_comments('post_id=' . $id);
    	$comments_by_type = &separate_comments($get_comments);
    	return count($comments_by_type['comment']);
    }
    
    function format_comment($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment; ?>
    
       <div id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
       <?php if ($comment->comment_approved == '0') : ?>
       <em><?php _e('Your comment is awaiting moderation.') ?></em><br />
       <?php endif; ?>
    
         <?php echo get_avatar($comment,$size='50' ); ?>
         <?php comment_text(); ?>
    
       <div class="comment-author vcard clear">
       <?php $from = $comment->extra_town;
             if($from !='') $mytown = ' (from ' . $from . ') '; ?>
         <span class="authorinfo">by <?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()) ?><?php echo $mytown; ?>
         on <a class="date" 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(__('e'),'  | ','') ?></span>
         <?php comment_reply_link(array_merge( $args, array('add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
       <!--/comment-author-->
       </div>
    
    <?php
    }

    Would that help you at all? You should be able to use your own classes and functions, and rearrange things as needed with this callback method.

  4. Jesse Friedman
    Member
    Posted 3 years ago #

    @doodledee You're awesome! Thanks a ton for your help!

  5. carehoodadmin
    Member
    Posted 3 years ago #

    Dear Jesse & Doodledee,

    I saw your thread and thought that you might be "experts" in customized comments.

    I have a question:
    Is it possible to have a Twitter/Facebook share button on every comment? (so not on every post/page, but on every comment). If yes, do you know how to do it?

    What I can imagine is that if people push these buttons, they will be directed to the comment, not to the whole post/page (but of course they can see the post and other comments too if they want)

    Thanks a lot before!
    I really hope for an answer

    Marina

Topic Closed

This topic has been closed to new replies.

About this Topic