WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Link to another author within someone else's post (19 posts)

  1. cozbaldwin
    Member
    Posted 3 years ago #

    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!

  2. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  3. cozbaldwin
    Member
    Posted 3 years ago #

    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.

  4. Digital Raindrops
    Member
    Posted 3 years ago #

    Try adding an echo and remove the whitespace.

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

    HTH

    David

  5. cozbaldwin
    Member
    Posted 3 years ago #

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

  6. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  7. FishDogFish
    Member
    Posted 3 years ago #

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

  8. cozbaldwin
    Member
    Posted 3 years ago #

    @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.

  9. cozbaldwin
    Member
    Posted 3 years ago #

    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.

  10. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  11. cozbaldwin
    Member
    Posted 3 years ago #

    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.

  12. cozbaldwin
    Member
    Posted 3 years ago #

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

  13. Digital Raindrops
    Member
    Posted 3 years ago #

    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

  14. cozbaldwin
    Member
    Posted 3 years ago #

    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.

  15. cozbaldwin
    Member
    Posted 3 years ago #

    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.

  16. cozbaldwin
    Member
    Posted 3 years ago #

    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.

  17. cozbaldwin
    Member
    Posted 3 years ago #

    In fact, just so it's well preserved, I'm gonna post it here, too:

    /* Start Get Author Link */
    function my_authors_meta($atts){
    ob_start();
            /* If the user passed an integer then good to go */
            if (is_numeric($atts[0])) {
                    $authorid = $atts[0];
                    echo '<a href="';
                    echo get_bloginfo('url');
                    echo '/author/';
                    echo the_author_meta('user_nicename', $authorid );
                    echo '/">';
                    echo the_author_meta('display_name', $authorid );
            echo '</a>';
            }
    $output_string = ob_get_contents();
    ob_end_clean();
    return $output_string;
    }
    add_shortcode('author', 'my_authors_meta');
    add_filter('my_authors_meta', 'do_shortcode');
    /* Start Get Author Link call [author id] */

    And then, yes, the shortcode of [author 7] will display user id #7's name and hyperlink it to their respective author page. Awesome.

  18. FishDogFish
    Member
    Posted 3 years ago #

    @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.

    You place custom fields at the bottom or the top, but yeah it's still limiting.

    Hopefully the next update to WP will include the ability to position the Custom Field more easily. A <!--Custom Field--> tag would be nice.

  19. Digital Raindrops
    Member
    Posted 3 years ago #

    Glad it is sorted now, and thanks for posting the final solution for others to use.

    Could you mark the topic as resolved.

    David

Topic Closed

This topic has been closed to new replies.

About this Topic