I want to add a custom “all posts by author” by authors name. How?

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!

Related posts

Leave a Reply

1 comment

  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' );