Skip Navigation

[Resolved] small change to comment metadata output

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add custom arguments to Layouts Comment Cell.

Solution:

the comment cell is also using wordpress function wp_list_comments() to get the comments, so you can use wordpress built-in filter hook to "wp_list_comments_args" to add your custom arguments.

Relevant Documentation:

https://developer.wordpress.org/reference/hooks/wp_list_comments_args/

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 3 voices.

Last updated by Paul Bowman 6 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1130748

I’m using the Layouts Comment Cell for comment function in a custom post type, in use e.g. here: hidden link

I want to modify metadata output so that only the comment date is shown, not ‘[date] at [time]’. I approached the problem the same way this person did, and realized as he did that simply adding a custom comments.php to my child theme doesn’t work:
https://toolset.com/forums/topic/how-to-use-add-a-custom-comments-php-to-my-child-theme/

All I need, in essence, is an alternative to the ‘( '%1$s at %2$s' )’ in wp-includes/class-walker-comment.php:

<div class="comment-metadata">
	<a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
		<time datetime="<?php comment_time( 'c' ); ?>">
			<?php
				/* translators: 1: comment date, 2: comment time */
				printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
			?>
		</time>
	</a>
	<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .comment-metadata -->

But I don’t know where to put this so that the Comment Cell will see it.

I am wondering if I’ll have to create a custom Comment Cell, as discussed here:
https://toolset.com/forums/topic/create-custom-comments-cell/

That seems like a lot of trouble to go to for such small modification.

#1131060

As you found out, the comments are not handled by Toolset Layouts but by WordPress.
Toolset Layouts displays jsut what WordPress generates and lets you customize some of the details.
https://toolset.com/documentation/user-guides/comments-cell/

To produce a Custom Comments Template is custom work that we cannot assist, however there is a great tutorial here:
hidden link

WordPress is not very sophisticated here.
It is also expressed in this comment:
hidden link

#1131486

Yes, thanks for those links, but I am familiar enough with that side of things. My question isn’t about styling the output, it has to do with changing the output itself.

I’m working from what’s outlined here: hidden link. The key thing, evidently, is access to wp_list_comments(). I gather that this can only be done by adding a custom comments cell in Layouts. So I’ve begun by following what Nigel helped Jennifer to do in the second forum link indicated in my question above, copying and modifying inc/cell_types/wpddl.cell_comments.class.php.

It looks like what I need, specifically, is a version of the comments cell that includes 'callback' in the $comments_defaults array in the ddl_render_comments_list() function. Basically:

function ddl_render_comments_list($comments, $post, $load_page='') {
    ob_start();
    …
    return ob_get_clean();

    if ( comments_open() ): …

        if ( !get_ddl_field( 'ddl_comment_nav_position' ) … { … }
        
        $comments_defaults = array();
        
        $comments_defaults['callback'] = 'my_modified_comments_output_function';

I’ve made some headway with setting this up. I’ve created a custom comments cell, and it does appear in Layouts on my site (the issue Nigel helped Jennifer with). But I have not yet been able to make an alternate version of the comments cell that does not break either the site as a whole or the page where the comments should load. I should say that I’m still very much a novice with PHP.

Should I go into further detail? My original question wasn’t about how to get a custom comments cell to work, of course.

#1131814

Hello,

Yes, you are right, the comment cell is also using wordpress function wp_list_comments() to get the comments, so you can use wordpress built-in filter hook to "wp_list_comments_args" to add your custom arguments, see wordpress document:
https://developer.wordpress.org/reference/hooks/wp_list_comments_args/

See similar thread here:
https://wordpress.stackexchange.com/questions/220549/how-to-add-an-inline-word-after-post-author-commenter-name

#1132347

I should have thought to look for a filter — the simple way to get at wp_list_comments(), obviously. But my experience with filters is limited as yet.

This got me close enough to the goal that I was able to figure out remaining PHP problems in my modified comments-output function. It’s working as I wanted it to now.

Thank you!

#1132348

Just a clarification: not everything works as I want it to yet. What’s solved is the specific problem of getting an alternative to the html given by html5_comment() in the Walker_Comment class. I have the result I wanted in a modified comment metadata output, but other expected output entailed there is missing. Evidently this involves dealing with the Walker_Comment class as a whole, which may be beyond my ability to resolve fully at present.