Forums

[resolved] Threaded comments: only one reply link per comment? (25 posts)

  1. kloooty
    Member
    Posted 1 year ago #

    Hi there,

    I'm trying to change the construct of the threaded comment system to fit my needs.

    I have already changed it insofar as all threaded comments are now inline with the main comment (so they are not indented anymore), but they are alternating between left and right alignment.

    My idea behind this is the following: Someone posts a comment, and if someone wants to reply to this comment, the reply is positioned directly beneath the first comment, using a different style - so it becomes clear this is response to the first comment, not a new one.

    I've pretty much already achieved this, but I do want to separate "main" comments from each other using a line. Please see the following example i quickly set up:

    http://img408.imageshack.us/i/comments.jpg

    Now this is the problem I ran into:

    I need to get rid of all the "REPLY" links WordPress adds to each threaded comment, so I can put only one comment for the whole "main" comment beneath it. Because in my comment structure, it is only possible to have a discussion on one particular main comment, not reply to a reply per se.

    I cant seem to get this to work though, I would need to use a if clause something like "if (nested comment) : do not show reply link, elseif (main comment) : show reply link at the end of the whole block".

    any idea how to do that?

    Thanks so much for your help!

  2. Joseph
    Member
    Posted 1 year ago #

    How about setting threaded comment to only 2 levels deep in Settings > Discussion?

  3. kloooty
    Member
    Posted 1 year ago #

    Mhm, would that work? I still have to make sure wordpress knows what comments are "main" comments and what are actually threaded comments, due to the different design: Threaded comments always alternate in alignment, while "main comments" are always positioned on the left. Plus, main comments are using the yellow speech bubble as an icon (which included the post number), while threaded comments use the smaller black speech bubble.

  4. Joseph
    Member
    Posted 1 year ago #

    Yes, it'll work. There are many class selectors used to differentiate the comments.

    For your main comments, you'll need to use:

    .depth-1 {
    }

    Because wordpress assigns odd/even class selectors regardless of depth, for 2nd level odd comments, you'll need to use:

    .even .odd,
    .odd .even {
    }

    And for even:

    .even .even,
    .odd odd {
    }
  5. kloooty
    Member
    Posted 1 year ago #

    Awesome, that works like a charm!

    One more thing though: How do I get the "Reply" link to be positioned right underneath the last "threaded" comment? Because currently it is obviously positioned right under the main comment. But I want it to look just like in my sample ...

    Got an idea for that too? :)

  6. Joseph
    Member
    Posted 1 year ago #

    If you're using default comments, add the following to your functions.php:

    add_filter('comment_reply_link','reply_link_mod',10,4);
    function reply_link_mod($string, $args, $comment, $post) {
    	return str_replace('div-comment','comment',$string);
    }
  7. kloooty
    Member
    Posted 1 year ago #

    What do you mean by "using default comments"? I added this to the functions.php but don't see any change, unfortunately :(

  8. Joseph
    Member
    Posted 1 year ago #

    Default as in not using a callback function to output the comments.

    So are you using a callback function? Cause I've tried that code before posting it here and it worked for me.

  9. kloooty
    Member
    Posted 1 year ago #

    ah ok. yes, i am using a callback function. I tried changing the code as follows:

    add_filter('comment_reply_link', 'newtheme' ,'reply_link_mod',10,4);
    function reply_link_mod($string, $args, $comment, $post) {
    	return str_replace('div-comment','comment',$string);
    }

    This kinda works, but my comment_reply_link is now gone completely and my page is a total mess ;-)

  10. Joseph
    Member
    Posted 1 year ago #

    Ok, forget about that code.

    You should have something like this in your callback function:

    <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>

    Replace it with:

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

    Depending on the structure of your comment, you might need to replace 'add_below' => 'comment'. This parameter determines which element the respond form will be placed after. For example, 'comment' refers to the element with id="comment-(comment id #)" and 'div-comment' refers to id="div-comment-(comment id #)".

  11. kloooty
    Member
    Posted 1 year ago #

    Ok, sounds easy! But I can't seem to get this to work, whatever ID I write into this, the reply link doesn't change it's position.

    Here is the whole code from my callback function, maybe you see a possibility? Obviously it's a structure problem.

    function mytheme_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 if ( $depth == '1' ) : ?> <div class="comment_wrapper_new"><div class="comment_count"></div><div class="titlebar_1">
    
    			<?php printf( __( '<span class"uppercase">%s</span> <span class="says">wrote on</span>', 'mytheme' ), sprintf( '<span class="uppercase">%s</span>', get_comment_author_link() ) );
    				/* translators: 1: date, 2: time */
    				printf( __( ' %1$s at %2$s', 'mytheme' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'mytheme' ), ' ' );
    			 ?>
    
                </div></div><div class="clear"></div> 
    
    			<?php elseif  ( $depth == '2' OR '3' OR '4' OR '5' OR '6' OR '7' OR '8' OR '9' OR '10' ) : ?> 
    
                <div class="comment_wrapper_new"><div class="titlebar_2_3_4"><img src="img/comment_reply.gif" alt="" border="0" />
    
    			<?php printf( __( '%s <span class="says">replied to this on</span>', 'mytheme' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) );
    				/* translators: 1: date, 2: time */
    				printf( __( ' %1$s at %2$s', 'mytheme' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'mytheme' ), ' ' );
    
    			?>
    
                </div></div>
    
    			<?php  
    
    		endif; ?>
    
    		</div><!-- .comment-author .vcard -->
    		<?php if ( $comment->comment_approved == '0' ) : ?>
    			<em><?php _e( 'Your comment is awaiting moderation.', 'mytheme' ); ?></em>
    			<br />
    		<?php endif; ?>
    
    		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"></a>
    
    		</div><!-- .comment-meta .commentmetadata -->
    
    		<div class="comment-body"><?php comment_text(); ?></div>
    
    		<div>
    			<?php comment_reply_link(array_merge( $args, array('reply_text' => 'Reply', 'add_below' => 'comment', '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:', 'mytheme' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'mytheme'), ' ' ); ?></p>
    	<?php
    			break;
    	endswitch;
    
    }
    
    $n ++; 
    
    endif;
  12. kloooty
    Member
    Posted 1 year ago #

    btw, thanks so much for all your help!

  13. Joseph
    Member
    Posted 1 year ago #

    Sorry, I was unclear. You don't write the ID, you use <?php comment_ID(); ?>. So for your particular structure, you should use 'add_below' => 'li-comment' referring to the main comment <li> element.

  14. kloooty
    Member
    Posted 1 year ago #

    I can't seem to get it to work, if I put in "li-comment" nothing changes ... feeling stupid ;-)

  15. Joseph
    Member
    Posted 1 year ago #

    Did you remove this?

    add_filter('comment_reply_link','reply_link_mod',10,4);
    function reply_link_mod($string, $args, $comment, $post) {
    	return str_replace('div-comment','comment',$string);
    }
  16. kloooty
    Member
    Posted 1 year ago #

    yes, i removed that.

    this is my function now:

    function mytheme_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 if ( $depth == '1' ) : ?> <div class="comment_wrapper_new"><div class="comment_count"></div><div class="titlebar_1">
    
    			<?php printf( __( '<span class"uppercase">%s</span> <span class="says">wrote on</span>', 'mytheme' ), sprintf( '<span class="uppercase">%s</span>', get_comment_author_link() ) );
    				/* translators: 1: date, 2: time */
    				printf( __( ' %1$s at %2$s', 'mytheme' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'mytheme' ), ' ' );
    			 ?>
    
                </div></div><div class="clear"></div> 
    
    			<?php elseif  ( $depth == '2' OR '3' OR '4' OR '5' OR '6' OR '7' OR '8' OR '9' OR '10' ) : ?> 
    
                <div class="comment_wrapper_new"><div class="titlebar_2_3_4"><img src="img/comment_reply.gif" alt="" border="0" />
    
    			<?php printf( __( '%s <span class="says">replied to this on</span>', 'mytheme' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) );
    				/* translators: 1: date, 2: time */
    				printf( __( ' %1$s at %2$s', 'mytheme' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'mytheme' ), ' ' );
    
    			?>
    
                </div></div>
    
    			<?php  
    
    		endif; ?>
    
    		</div><!-- .comment-author .vcard -->
    		<?php if ( $comment->comment_approved == '0' ) : ?>
    			<em><?php _e( 'Your comment is awaiting moderation.', 'mytheme' ); ?></em>
    			<br />
    		<?php endif; ?>
    
    		<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"></a>
    
    		</div><!-- .comment-meta .commentmetadata -->
    
    		<div class="comment-body"><?php comment_text(); ?></div>
    
    		<div>
    			<?php comment_reply_link(array_merge( $args, array('reply_text' => 'Reply', 'add_below' => 'li-comment', '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:', 'mytheme' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'mytheme'), ' ' ); ?></p>
    	<?php
    			break;
    	endswitch;
    
    }
    endif;
  17. Joseph
    Member
    Posted 1 year ago #

    I'm sorry, I just realised I made a huge mistake. I miss read your reply and thought you wanted to move the respond form...

    I've never moved the link before so I'll have to give it a try.

  18. kloooty
    Member
    Posted 1 year ago #

    ah ok. no problem ;-)

    I want to move the reply link only, not the form. But this modification of comment_reply_link is the reply link, isn't it? if I change the reply_text e.g. it works quite well. So the only thing not working is moving it using the "add_below" ...

  19. Joseph
    Member
    Posted 1 year ago #

    add_below is for the form.

    I'm in the middle of trying out adding an end-callback function to put the reply link just before the </li> tag of the main comment.

  20. Joseph
    Member
    Posted 1 year ago #

    Ok, I've got it.

    Add the end-callback parameter, calling the following function, to wp_list_comments

    function comment_end_callback($comment, $args, $depth) {
    	if ($depth == 0) { ?>
    		<div>
    		<?php comment_reply_link(array_merge( $args, array('reply_text' => 'Reply', 'add_below' => 'li-comment', 'depth' => 1, 'max_depth' => $args['max_depth'])), $comment->comment_ID); ?>
    		</div>
    	<?php }
    	echo "</li>\n";
    }

    You'll need to remove reply link from your callback function.

  21. kloooty
    Member
    Posted 1 year ago #

    Cool thanks. But how can I add two callbacks to wp_list_comments?

    this:

    wp_list_comments( array( 'callback' => 'twentyten_comment' ), array( 'callback' => 'comment_end_callback' ) );

    doesn't work ...

  22. kloooty
    Member
    Posted 1 year ago #

    mhm ok just realized what I did up there doesn't make sense.
    I did it this way:

    wp_list_comments( array( 'callback' => 'twentyten_comment', 'comment_end_callback' ) );

    But the reply link won't show up ... I added the function to the bottom of the functions.php thats correct, isn't it?

    a million thanks!!

  23. Joseph
    Member
    Posted 1 year ago #

    This:

    wp_list_comments( array( 'callback' => 'twentyten_comment', 'end-callback' => 'comment_end_callback' ) );

    You can add the function anywhere in your functions.php

  24. kloooty
    Member
    Posted 1 year ago #

    Awesome! Works perfectly. Thanks so much for all your help, really appreciated! :)

  25. Joseph
    Member
    Posted 1 year ago #

    You're welcome.

    Can you put this as resolved? Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic