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 am trying to display current post author link above the loop (before loop starts) with this tag the_author_posts_link() but it's not displaying the author post link. Anyone please help me.

Edited question:

So I want author post links like this

September 17th, 2008 by (here will be author name with post link)

Like

September 17th, 2008 by Jatin Soni

This is the author meta I belive

share|improve this question
    
use get_author_posts_url($id) instead.. –  amit Aug 9 '12 at 17:31
    
It's not working. May be I explained wrong but please check my edited question –  pixelngrain Aug 9 '12 at 17:36
    
that is post date right ? –  amit Aug 9 '12 at 17:38
    
Yes that's right I am trying to display post meta above the loop –  pixelngrain Aug 9 '12 at 17:40
add comment

2 Answers

up vote 3 down vote accepted

It make use of global variable $post to get author id of current post. Using that this function returns the author url.

Note -

Make sure you put this in condition ( is_single() ) so it only print author url on single.php.

<?php echo get_author_posts_url( $post->post_author ); ?>

Update -

<?php $username = get_userdata( $post->post_author ); ?>    
<a href="<?php echo get_author_posts_url( $post->post_author ); ?>"><?php echo $username->user_nicename; ?></a>

This will work, but I'll update my answer if I found more efficient method.

share|improve this answer
    
Its echo the actual url but I want the author name with its post link (archive) please check my edited question. –  pixelngrain Aug 9 '12 at 17:37
    
I've updated answer, I'll update again if found more efficient method. –  amit Aug 9 '12 at 18:01
    
This is what I was looking for. Thanks a lot Amit and Happy Janmashtami. Jai Shri Krishna :) –  pixelngrain Aug 9 '12 at 18:11
add comment

You have to use the function in the loop.

Else it won't output anything.


Edit

First, you might want to retrieve a list of links to all authors.

All authors:

You can use wp_list_authors() for this:

$authors = wp_list_authors( array(
     'echo'       => false
    ,'feed_image' => false
    ,'feed'       => true
) );
// do something with ...
// $authors;

This leaves you with a list of all authors and is similar to what @amit wrote.

A single author link

This is similar to what @amit wrote.

Setup the user data with setup_userdata( $author_id );. The $author_id can be retrieved with the $post global like this:

global $post;
$author = setup_userdata( $post->post_author );
echo get_author_posts_url( $post->post_author, $author->user_nicename ); 
share|improve this answer
    
I know that but I want to display post author info above the loop for some reason. How can I do that? –  pixelngrain Aug 9 '12 at 17:31
    
See update. @amit and me answered at pretty much the same time, so please mark his answer as solution (still appreciate an upvote). –  kaiser Aug 9 '12 at 17:40
    
This is giving url but I want author display name with link. Like September 17th, 2008 by Jatin Soni –  pixelngrain Aug 9 '12 at 17:52
1  
Amit's edited answer works but I really appreciate your help and effort so up voted :) thanks again –  pixelngrain Aug 9 '12 at 18:12
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.