Inside an 'About The Author' within the loop on single.php, I want to have a link like the following:
<a href="%AUTHOR-LINK-HERE%">View All Posts From This Author</a>
Basically a modified version of this WP function:
<?php the_author_posts_link(); ?>
But without having wordpress printing the 'href' and 'author name'. I only want it to return the URL of the author WHILE using the users default permalink structure defined in their WP settings.
Thanks,
Monster Coder answers:
You can use:
get_the_author_link()
Rather than printing, it will return you the LINK! So you will be able to use it as you like :).
Aaron comments:
This displays the authors website url. I meant for it to output the url to the authors post page.
Monster Coder comments:
ops!
then you will need
get_author_posts_url()
seems MagoryNET written well for that :)!
Monster Coder comments:
Inside the loops you can simply use it:
get_author_posts_url($post->post_author);
that's it
Aaron comments:
get_author_posts_url($post->post_author);
Used inside of the loop, this makes the link to the current post (just tested).
Monster Coder comments:
is it? I have given you after testing. I got link like:
http://localhost/wordpress30/?author=1
when I copied I got posts of this users!
i have used it inside a function this way:
function func_name(){
global $post;
echo get_author_posts_url($post->post_author);
}
Aaron comments:
function func_name() {
global $post;
echo get_author_posts_url($post->post_author);
}
This works, thanks!
Cosmin Popovici answers:
<?php the_author_url(); ?>
or
<?php the_author_link(); ?>
<strong>EDIT</strong>
Ok, so MagoryNET got it right, with one small mod (you got a concatenation issue there mate :) ):
<?php
global $user_ID;
$user_info = get_userdata($user_ID);
$current_link = get_author_posts_url($user_id,$user_info->display_name);
?>
<a href="<?php echo $current_link ?>">by username</a>
This generates <a href="http://yoursite.com/author/username">by username</a>
Was that what you were after?
Aaron comments:
This displays the authors website url. I meant for it to output the url to the authors post page.
MagoryNET answers:
Add something like this:
<?php
global $user_ID;
$user_info = get_userdata($user_ID);
$current_link = get_author_posts_url($user_id,$user_info->user_nicename);
echo '<a href="'.$current_link.'">View All Posts From This Author</a>;
?>
PS. Corrected. It's basicly a version of the_author_posts_link modified to change the text in the link.
Aaron comments:
This displays the authors name, which I said I do NOT want...
MagoryNET comments:
It does not.
Aaron comments:
All this does is add the 'Display Name' of the author to the URL, which takes me to a 404 page, because it does not check to see what my permalink structure is.
MagoryNET comments:
I had a small error, I corrected know. There should be nicename not display_name in the get_author_posts_url.
Aaron comments:
This seems so close. The only issue I am having with this now, is that if I change my permalinks to the wordpress default, it is actually assigning an author id of '0' instead of my actual id which is '1'. Any ideas?
This is the code I am using:
function view_author_posts() {
global $user_ID;
$user_info = get_userdata($user_ID);
$current_link = get_author_posts_url($user_id,$user_info->user_nicename);
echo $current_link;
}
<a href="<?php view_author_posts(); ?>">View All Posts From This Author</a>
MagoryNET comments:
Yeah, another mistake. user_ID is logged in user, not the author. Try this:
function view_author_posts() {
global $authordata;
$current_link = get_author_posts_url($user_id,authordata->user_nicename);
echo $current_link;
}
MagoryNET comments:
I responded too fast. Another little fix:
function view_author_posts() {
global $authordata;
$current_link = get_author_posts_url($authordata->ID,authordata->user_nicename);
echo $current_link;
}
Nilesh shiragave answers:
Yes MagoryNET right solution
Aaron comments:
<blockquote>WordPress.org - "Displays the link, where the default link text value is the user's <strong>Display name publicly as field</strong>."</blockquote>
This function has no parameters. And therefore does not do what I am asking, because it outputs the entire a/link tag and anchor text, which I said above that I do NOT want.
regards,