logo

$5
Display Author Link (URL Only, Without Authors Name)

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,

Aaron | 08/31/10 at 3:00am | Edit


(4) Possible Answers Submitted...

  • avatar
    Last edited:
    08/31/10
    3:25am
    Cosmin Popovici says:

    <?php the_author_url(); ?>


    or

    <?php the_author_link(); ?>


    EDIT

    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?

    Previous versions of this answer: 08/31/10 at 3:18am | 08/31/10 at 3:25am

    • 08/31/10 3:09am

      Aaron says:

      This displays the authors website url. I meant for it to output the url to the authors post page.

  • avatar
    Last edited:
    08/31/10
    3:48am
    Monster Coder says:

    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 :).

    Previous versions of this answer: 08/31/10 at 3:07am

    • 08/31/10 3:10am

      Aaron says:

      This displays the authors website url. I meant for it to output the url to the authors post page.

    • 08/31/10 3:19am

      Monster Coder says:

      ops!

      then you will need

      get_author_posts_url()


      seems MagoryNET written well for that :)!

    • 08/31/10 3:22am

      Monster Coder says:

      Inside the loops you can simply use it:

      get_author_posts_url($post->post_author);

      that's it

    • 08/31/10 3:28am

      Aaron says:

      get_author_posts_url($post->post_author);


      Used inside of the loop, this makes the link to the current post (just tested).

    • 08/31/10 3:42am

      Monster Coder says:

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

    • 08/31/10 3:48am

      Aaron says:


      function func_name() {
      global $post;
      echo get_author_posts_url($post->post_author);
      }


      This works, thanks!

  • avatar
    Last edited:
    08/31/10
    3:40am
    MagoryNET says:

    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.

    Previous versions of this answer: 08/31/10 at 3:07am | 08/31/10 at 3:38am | 08/31/10 at 3:38am | 08/31/10 at 3:40am

    • 08/31/10 3:16am

      Aaron says:

      This displays the authors name, which I said I do NOT want...

    • 08/31/10 3:20am

      MagoryNET says:

      It does not.

    • 08/31/10 3:31am

      Aaron says:

      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.

    • 08/31/10 3:38am

      MagoryNET says:

      I had a small error, I corrected know. There should be nicename not display_name in the get_author_posts_url.

    • 08/31/10 3:43am

      Aaron says:

      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>

    • 08/31/10 3:45am

      MagoryNET says:

      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;

      }


    • 08/31/10 3:46am

      MagoryNET says:

      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;



      }

  • avatar
    Last edited:
    08/31/10
    3:24am
    Nilesh shiragave says:

    Yes MagoryNET right solution

    Previous versions of this answer: 08/31/10 at 3:20am | 08/31/10 at 3:21am | 08/31/10 at 3:21am | 08/31/10 at 3:24am

    • 08/31/10 3:25am

      Aaron says:

      WordPress.org - "Displays the link, where the default link text value is the user's Display name publicly as field."


      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,

This question has expired.





Current status of this question: Completed