How do I link to authors post outside of loop (2 posts)

  1. iamthestreets
    Posted 1 year ago #


    I am using UberMenu and they have been very helpful, but we have not been able to figure this out.

    They have a shortcode to display recent post in the menu with image and title.

    I want to add the author of the post under the title linked to the authors post.
    Here is the current code:

    $post_url = get_permalink($post->ID);
    		$author_name = get_the_author_meta('display_name', $post->post_author );
    $html.= '<li>'.	$image.
        				'<div class="wpmega-postlist-title">
        				<a href="'.$post_url.'">'.$post->post_title.'</a></br>
        				<a href="'.esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ).'">'.$author_name.'</a>

    If you mouse over the sports menu tab and mouseover the author name while on the home page you will see it links correctly, but if you click into any other page if removes the author fro the URL.

    Site: http://mystreetlife.com/home

  2. iamthestreets
    Posted 1 year ago #

    Got it working by adding this:
    $author_id = $post->post_author;

    And changing this to:
    <div class="wpmega-post-author"><a href="'.get_author_posts_url($author_id).'"><span>by '.$author_name.'</span></a></div>

    Note: putting code in backsticks is not working

Topic Closed

This topic has been closed to new replies.

About this Topic