walker class – bbird.me http://bbird.me WordPress quick tips Wed, 08 Aug 2018 16:39:07 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 How to create custom comment walker class in WordPress http://bbird.me/how-to-create-custom-comment-walker-class-in-wordpress/ http://bbird.me/how-to-create-custom-comment-walker-class-in-wordpress/#comments Fri, 03 Jun 2016 20:29:46 +0000 http://bbird.me/?p=513 There are several walker classes in WordPress – I don’t actually know how many there are because I tend to

Post How to create custom comment walker class in WordPress je prvi puta viđen na bbird.me.

]]>
There are several walker classes in WordPress – I don’t actually know how many there are because I tend to browse the source code only if I need to change something, just as others I guess :). Regardless, I’m sure that custom navigation walker class is probably the most used and customized WordPress walker class. But recently I had a project where I needed to change meta info which appears next to Gravatar image in the comments section.  When it comes to any walker classes in WordPress, I guess that the main idea is that you take the whole code, put it into functions.php or elsewhere and use function callback to call it. I guess…

So first things first – the function which calls comments is wp_list_comments() which also accepts number of parameters. One of them is ‘walker’. In order to call walker, it would be nice to create one. You can call it like this:

wp_list_comments( array(
  'style'       => 'ol',
  'short_ping'  => true,
  'avatar_size' => 82,
  'walker' => new bruno_walker_comment
) );

But as I said, we need a walker:

That’s a lot of code, right? But don’t worry,  About 99% of that code is copy-paste from class-walker-comment.php file, which lives in wp-includes folder. The only change I did was this:

<div class="comment-metadata">

<?php 
$user_id=$comment->user_id;
?>
<p class="commenter-bio"><?php the_author_meta('description',$user_id); ?></p>
<p class="commenter-url"><a href="<?php the_author_meta('user_url',$user_id); ?>" target="_blank"><?php the_author_meta('user_url',$user_id); ?></a></p>
						
</div><!-- .comment-metadata -->

I used this code to get some data ( biographical info and user URL) from Users section. So to conclude, if you want to make some bigger changes in the comments section, walker class is the way to go. All you need to do is copy the original walker and extend it with your own changes.

Post How to create custom comment walker class in WordPress je prvi puta viđen na bbird.me.

]]>
http://bbird.me/how-to-create-custom-comment-walker-class-in-wordpress/feed/ 1