Categories
General

How to change things on the comment template

In my case, I wanted to change the text in the new threaded comments from “Reply” to “Reply to this comment” – sounds simple enough, right?

First: Grab the example function from this Codex page and add it to your theme’s functions.php file, changing the function name to suit.

Next: Locate the wp_list_comments function call in your theme’s comments.php file. If you don’t see it there you’ll need to consult the Codex to get your theme up to date. Once you’ve found or added that function call, change it to use your new custom function instead of the default, like this:

wp_list_comments('type=comment&callback=mytheme_comment');

Finally: It’s clear enough how to modify the function to do some things, but in my case I wanted WP’s comment_reply_link function to display “Reply to this comment” instead of just “Reply” – it’s not clear how to do that though. The example function takes some arguments, so I decided to poke around to see if maybe it accepts more. Turns out you can set a custom reply_text by adding to the array of arguments like this:

comment_reply_link(array_merge( $args, array('reply_text' => 'Reply to this comment', 'depth' => $depth, 'max_depth' => $args['max_depth'])))

Other defaults include: add_below, respond_id, login_text, depth before after. Not sure what they all do yet…

Update: The get_avatar call in the example function from the Codex has a placeholder $default set, so it doesn’t work right for users without gravatar accounts. I just removed the placeholder so my get_avatar call looks like this instead:

< ?php echo get_avatar($comment,$size='48'); ?>

Categories
General

Showing all of an author’s posts on an author archive

One of my family blog authors just noticed that the author archive pages weren’t showing all of an author’s posts. It turns out that the sample author template in the WP Codex that I’d borrowed only shows the number of posts from WordPress’ Settings – in our case 5 posts – and the sample doesn’t include navigation links. Caveat emptor on the Codex examples of course, but even once I noticed the problem it wasn’t all that apparent how to fix it. I wanted to display more (actually all) of an author’s posts because it’d be pretty tedious to use nav links to go through hundreds of posts. After some Codex browsing I figured out that re-doing the query just before the Loop works:

<?php query_posts('author=' . $curauth->ID . '&showposts=-1'); ?>

This is probably running two post queries and highly inefficient, but it does work – I added a little counter to the Loop to double-check.