Categories
General

Linking to a commenter’s author page

Normally, when a logged-in user leaves a comment, a link pointing to the URL in their profile is added to the comment. This is fine, but what if you’ve set up an author template to serve up fancy author pages? Wouldn’t it be better to link there instead? If your theme already has a replacement wp_list_comments function, it’s pretty easy.

Add something like this to the top of your comment callback function in your theme’s functions.php:

$comment_author = get_comment_author();
$comment_author_link = get_comment_author_link();
if (!empty($comment->user_id)){
  if ($author_url = get_author_posts_url($comment->user_id)) {
    $comment_author_link = '<a href="' . $author_url . '">' . $comment_author . '</a>';
  }
}

Now you can echo out $comment_author_linkĀ  wherever you had the standard author link. If the commenter is a logged-in user, the link will point to their fancy author page – otherwise it’ll just point to the commenter’s URL as usual.

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.