WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Link to another author within someone else's post

[Resolved] Link to another author within someone else's post

  • Ok. This seems so stupid. But I’ve searched and searched for hours and cannot find out how to do this.

    I am building a site which reviews plays. Some of these reviews are done by two people called “HE SAID/SHE SAID”

    I’m looking for a way to keep the author of the post as HE SAID/SHE SAID but within the post, link to the two specific authors, who already are users(authors) on the site. But I cannot find the way to link to a specific author’s ID.

    EXAMPLE POST:

    =========================
    Review of Phantom of The Opera
    Author: He said/She said

    We’ve sent two people out to review Phantom of The Opera at The Local Playhouse and below you’ll find their individual reviews!

    HE SAID by: Bob Barker (Bob Barker would be linked to his author page)
    “It sucked”

    SHE SAID by: Betty White (Betty White would be linked to her author site)
    “I loved it!”
    =========================

    Ok. So I thought I was looking for something like by <a href=" <?php get_the_author_link(7); ?> ">Bob Barker</a> since Bob’s author ID# is 7…. but that’s not working.

    Please help!

Viewing 15 replies - 1 through 15 (of 18 total)
  • get_the_author_link() will not take an argument (This tag does not accept any parameters.), so you cannot pass in an id, have a look at The Author Meta

    <a href=" <?php the_author_meta('user_url', 7 ); ?> ">Bob Barker</a>

    HTH

    David

    Thanks for the reply, though it doesn’t seem to be working. It’s passing the current post’s URL + the actual php code as printed above (unrendered) + a good portion of the article itself in the browser’s URL bar… and of course, I land on a 404.

    I am even using Exec-PHP plugin which allows php to be used in widgets, posts, and pages, when necessary, which I don’t even think it is in this case.

    Try adding an echo and remove the whitespace.

    <a href="<?php echo the_author_meta('user_url', 7 ); ?>">Bob Barker</a>

    HTH

    David

    Nope. Sorry, but thank you. It’s still doing the same thing.

    Try it in stages, just see if we can get the authors name, make sure you have the ID of a user where the users Role = Author

    Try this first to see if you get any data returned.

    <?php the_author_meta('display_name', 7 ); ?>
    or
    <?php echo the_author_meta('display_name', 7 ); ?>

    David

    Here’s a link to an article on Using Custom Fields that might help.

    @adeptris I’ve realized one error I was having with the executing of the PHP that had to do with the Exec-PHP plugin. So I’ve fixed that, I think. Now…. Your latest suggests DO print the name of the author I want. They are, of course, not hyperlinked to his author page, though.

    @fishdogfish: Thanks, but I’m looking to add these things in the middle of the post, and as far as I can tell, adding Custom Fields is only good for adding data down at the bottom of each post.

    Also, @adeptris, Ive gone back and used your original suggestions now that the php thing is under control (i think) but all it does is link to the current page. It goes nowhere.

    It makes no sense… but: <a href="<?php echo the_author_meta('user_url', 7 ); ?>">Bob Barker</a> just refreshes the page for me.

    Ahhh!
    The user_url is from the users information and not the author!
    A work around would be to populate the users websote on the user page.

    user_nicename should return the ‘slug’ test this it should return ‘bob-barker’

    www.yoursite.com/author/bob-baker/

    <a href="<php echo get_bloginfo('url') ?>/author/>
    <?php echo the_author_meta('user_nicename', 7 ); ?>">
    <?php echo the_author_meta('display_name', 7 ); ?>
    </a>

    Not sure if it is ‘url’

    David

    OK… that makes sense and it does work… but I don’t want it to link to the User’s website, I want it to link to the author’s bio page (I have author pages set up which show the userpic, bio, and posts by that author)

    I have been trying to replace user_url with such things as:
    get_author_posts_url
    the_author_link

    but so far, no luck.

    EDIT: just saw your new edit… but can’t see most of it due to the code being rendered and not displayed. Hope you can change that because i think you’re onto something.

    user_nicename does print.

    Putting it all together…

    <a href="<php echo get_bloginfo('url') ?>/author/>
    <?php echo the_author_meta('user_nicename', 7 ); ?>">
    <?php echo the_author_meta('display_name', 7 ); ?>
    </a>

    prints nothing. 🙁

    I have it working as a function, but cannot get it to position where I want it!

    I have created a function to use a shortcode in the post, and it is working, have a look and see if you can work it from there.

    I am off for the night now it is 23:00pm

    I added the function to functions.php, and in the post I just add:

    [author 7] this returns a linked name, but it goes to the top of the page, so the code needs changing to wrap the link so it stays where you enter it.

    Let us know how you resolve it 🙂

    HTH

    David

    It’s crazy. What you suggested makes perfect sense and yet it doesn’t print anything.
    And I even tried replacing the display_name function with a few random letters and it still didnt print which leads me to believe the issue is somewhere in the link which is preventing it from printing whatever’s in the A tag.

    Ahh! yes yes yes! That function worked, but you’re right – it’s displaying at the top of the page. I am no good with php but I will tinker and see if I can do SOMEthing about that. Thanks for your help thus far. I appreciate it a lot.

    Oh my goodness.
    So I found this article: http://www.amberpanther.com/knowledge-base/set-up-wordpress-shortcode-handler-function-return-echoed-strings/

    And, like a blind man walking through a maze, I gave it a shot — and lo and behold… it works! So far, at least. Ill add my edits to your pastebin.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Resolved] Link to another author within someone else's post’ is closed to new replies.
Skip to toolbar