WordPress.org

Ready to get started?Download WordPress

Forums

Link to author's posts without displaying their name (6 posts)

  1. jimmiejo
    Member
    Posted 6 years ago #

    In my category, search, etc... templates I'm displaying an image for each of the authors:

    <img src="<?php bloginfo('template_url'); ?>/images/authors/<?php the_author_ID(); ?>.gif" alt="<?php the_author(); ?>" />

    I'd like to wrap that in an href that links to each author's page (www.mydomain.com/author/name). The only function I could find that returns that link is the_author_posts_link. Unfortunately, it automatically wraps that link around their name and there's no parameter (that I can see) to only display their link without the name.

    Is there any way to just echo the link to their author page?

  2. MichaelH
    Member
    Posted 6 years ago #

    You mean like echo get_the_author_url()?

  3. Ivovic
    Member
    Posted 6 years ago #

    wouldn't that link to their website as specified in their profile?

    anyway, since all author links are the same, it should be a fairly simple matter to construct the permalink based on the author's display name if using pretty permalinks (or based on their ID maybe? if not... I dunno what the format is for ugly permalinks, but whatever it is, it'll be similar for all authors).

    I couldn't find a function to return just the URL to an author's posts.

  4. jimmiejo
    Member
    Posted 6 years ago #

    Michael,
    Like Ivovic said, that would echo the author's url they set in their profile. Not quite what I'm after.

    Using this href:

    <a href="<?php bloginfo('url'); ?>/author/<?php the_author_nickname(); ?>"></a>

    ...around the author's image does the trick of linking to their author profile. For SEO purposes, it'd probably be best if you/I make sure all the author nicknames are lowercase and contain no spaces, otherwise you'd see http://www.domain.com/author/Michael

    Luckily, I don't need to display the author's nickname as text in my template, the avatar is all I need so I think this should do the trick.

    Thanks for your quick replies guys.

  5. Ivovic
    Member
    Posted 6 years ago #

    to avoid having to set nicknames or keep track of your users, you can turn the above into:

    <a href="<?php bloginfo('url'); ?>/author/<?php echo strtolower(get_the_author()); ?>"></a>

    this makes sure that the link is valid, as the link relies on the display name as chosen, not the nickname field. The strtolower() part sends it to lowercase.

  6. StrangeAttractor
    Member
    Posted 6 years ago #

    @Ivovic

    I've just tried your solution, and it seems to work.

    But I have a question about it. On the site I'm working on, the author's pages have a link that looks like this:

    blogurl/author/john-smith

    There are hyphens between the first and last names.

    In the solution you posted, however, the link gets returned like this:

    blogurl/author/john smith

    with a space instead of a hypen, which gets interpreted by the browser like this:

    blogurl/author/john%20smith

    It pulls up the correct author url, but I'm just wondering if there are any problems with the fact that it's not using the hyphens. Are hyphens and spaces considered the same in the url?

    (*grumble* I'm also wondering why the hell WP has never introduced a template tag that simply returns the unlinkified author URL...)

Topic Closed

This topic has been closed to new replies.

About this Topic