- This topic has 15 replies, 2 voices, and was last updated 7 years, 3 months ago by Tom.
-
AuthorPosts
-
January 3, 2017 at 11:20 am #260336January 3, 2017 at 7:07 pm #260436TomLead DeveloperLead Developer
Hmm, I actually can’t think of a way to do this. You might have luck posting over at Stack Exchange though: http://wordpress.stackexchange.com/
January 12, 2017 at 4:34 am #263302MichalHi again,
I got a response with a proper answer which does the job ๐
However I have a custom php function which changes the comments’s look.
function generate_disable_comment_fields($fields) { unset($fields['url']); unset($fields['email']); unset($fields['author']); return $fields; } add_filter('comment_form_default_fields','generate_disable_comment_fields'); if ( ! function_exists( 'generate_comment' ) ) : /** * Template for comments and pingbacks. * * Used as a callback by wp_list_comments() for displaying the comments. */ function generate_comment( $comment, $args, $depth ) { $GLOBALS['comment'] = $comment; $args['avatar_size'] = apply_filters( 'generate_comment_avatar_size', 50 ); if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?> <li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>> <div class="comment-body"> <?php _e( 'Pingback:', 'generate' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'generate' ), '<span class="edit-link">', '</span>' ); ?> </div> <?php else : ?> <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>> <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> <footer class="comment-meta"> <div class="comment-author-info"> <div class="entry-meta comment-metadata"> <?php edit_comment_link( __( 'Edit', 'generate' ), '<span class="edit-link"> ', '</span>' ); ?> </div><!-- .comment-metadata --> </div><!-- .comment-author-info --> <?php if ( '0' == $comment->comment_approved ) : ?> <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'generate' ); ?></p> <?php endif; ?> </footer><!-- .comment-meta --> <div class="comment-content"> <?php comment_text(); ?> <?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => '<span class="reply"> ', 'after' => '</span>', ) ) ); ?> </div><!-- .comment-content --> </article><!-- .comment-body --> <?php endif; } endif; // ends check for generate_comment()
and a piece of code from comments.php file look like this:
wp_list_comments( array( 'callback' => 'generate_comment' ) );
How to change that so the comments section look like before and I could add this additional content every x lines?
To do that you have to compose
wp_list_comments( array( 'callback' => 'generate_comment' ) );
and
wp_list_comments( [ '_inject_period' => 5, '_inject_content' => [ 'AAA', 'BBB', 'CCC' ], ] );
somehow. But how? Could you help with that?
January 12, 2017 at 12:12 pm #263480TomLead DeveloperLead DeveloperYou would need to use a child theme, then copy comments.php from the parent theme and add it to the child theme.
Then you can make changes to the code in there without worrying about updates losing your changes.
January 12, 2017 at 1:28 pm #263513Michalehh you don’t get it. I know how it works.
I am not able (because of my php skills) to replace standard
wp_list_comments( array( 'callback' => 'generate_comment' ) );
with
wp_list_comments( [ '_inject_period' => 5, '_inject_content' => [ 'AAA', 'BBB', 'CCC' ], ] );
as developer from stackexchange said because I will loose comments.php customizations (nicknames and dates)
and from my point of view it can be remained (both comments.php styling – lack nicknames and dates and additional content between them) by merging this two pieces of code together somehow.
but I don’t know how because I’m not a php developer. You are so that I thougth you come with an idea because you helped me to style the comments some time ago.
DO you understand now? ๐
January 12, 2017 at 8:19 pm #263586TomLead DeveloperLead Developeras developer from stackexchange said because I will loose comments.php customizations (nicknames and dates)
Not if you copy comments.php and place it in your child theme. That’s the only way to edit that file and replace that function without losing your changes when you update.
January 12, 2017 at 9:46 pm #263611MichalBut I am replacing that function in a child theme (comments.php) as I said.
January 12, 2017 at 10:56 pm #263623MichalWe have here
'callback' => 'generate_comment'
which links to my custom php file and when I remove it by replacing it with code which I got from another developer it will not work. It works with default comments.php file thoughJanuary 12, 2017 at 10:58 pm #263624TomLead DeveloperLead DeveloperCan you show me the contents of your child theme comments.php file in a pastebin or a gist? If your child theme has that file and the function they say to replace is replaced, then it should work as long as the code in that answer is correct.
If not then you may need to find another method.
January 12, 2017 at 11:00 pm #263625TomLead DeveloperLead DeveloperSo what if you merge the args? Keep the generate_comment callback but add the other parts as well instead of fully replacing it.
Never done this so I’m not sure it will work – purely guessing.
January 12, 2017 at 11:01 pm #263626MichalI tried but I could make a mistake with “” ‘ ] etc Can you point me an example of how to merge this to work together?
January 12, 2017 at 11:10 pm #263627Michaland here is my comments.php file
January 12, 2017 at 11:22 pm #263631Michaland custom functions regarding
'callback' => 'generate_comment'
January 12, 2017 at 11:42 pm #263636TomLead DeveloperLead DeveloperSo you would replace:
wp_list_comments( array( 'callback' => 'generate_comment' ) );
With:
wp_list_comments( array( 'callback' => 'generate_comment', '_inject_period' => 5, '_inject_content' => array( 'AAA', 'BBB', 'CCC' ), ) );
Again, I have no idea if this will work or not.
January 12, 2017 at 11:56 pm #263642MichalIt worked. Just as I thougth – I made the same but with a tiny mistake.
I made a small donation to thank you for your support.
Thanks again
-
AuthorPosts
- You must be logged in to reply to this topic.