Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom display of meta-info (authors name, date and categories). So, I want to display a custom link to all posts by author. By theme default I have this <?php the_author_posts_link(); ?> which displays author name and if you press on it you get what I want. On the index.php actually it is what I want, but on single.php I would like to have something like "view all pages by author" text and if you would press on it, it should do exactly the same as adding <?php the_author_posts_link(); ?>. where should I start with this issue? Thanks!

share|improve this question
1  
You can't do that if your blog is hosted on wordpress.com –  scribu Aug 12 '11 at 13:21
    
I have a custom host –  user385917 Aug 12 '11 at 13:24
2  
Then why did you tag the question with 'wordpress.com'? Anyway... –  scribu Aug 12 '11 at 13:27
add comment

1 Answer 1

Attach a filter that only outputs a different link when you're on single.php:

function wpse25725_author_posts( $link )
{
    // abort if not on single.php
    if ( ! is_single() )
        return;

    // modify this as you like - so far exactly the same as in the original core function
    // if you simply want to add something to the existing link, use ".=" instead of "=" for $link
    $link = sprintf(
        '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
        get_author_posts_url( $authordata->ID, $authordata->user_nicename ),
        esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
        get_the_author()
    );

    return $link;
}
add_filter( 'the_author_posts_link', 'wpse25725_author_posts' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.