• What I’m trying to do sounds simple but it is kicking my rear. I have some regular pages that I’m using for author bios and down below in the theme, I’d like to show some recent posts from that author.

    So here’s an example of a columinst bio page: https://www.libertynewsdaily.com/lrt/columnists/ron-paul/

    Here’s an archive of this authors posts:
    https://www.libertynewsdaily.com/lrt/author/ron-paul/

    Note that the slugs are exactly the same. I was wondering if there was a way to do a query and use something like /author/<?php echo $post->post_name; ?> to display like five or so of the author’s posts.

    Any ideas, I’d appreciate your help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter vectyr

    (@vectyr)

    Wow, that’s pretty close to what I’m looking for. But I think that code is for the author profile, whereas I am using a page for an author profile.

    You can query post from an author on a page as well…
    Just for me to understand:

    You have created a page like this: https://www.libertynewsdaily.com/lrt/columnists/ron-paul/ which uses the page.php to be shown? And there you want to show the last 5 Posts of that specific author?

    Thread Starter vectyr

    (@vectyr)

    Yeah, you’ve got it. It’s a page but it’s using a custom template instead of page.php.

    //edit
    pls wait need some corrections ??

    Ok…. hope thats it now ??

    Add this in your custom template after the content loop…There is on important thing… the page title of the authors bio page musst exactly fit to the authors name/slug.

    e.g.
    Is the authors name is “Simon D. Connor” his slug will be “simon-d-connor” so you have to use “Simon D. Connor” for the page title as well, so that the page slug will also be “simon-d-connor”… as you wrote it at the beginning…. do you know what I mean? its not that great solution… but i guess this will work for you…

    <ul>
      <?php
        //slug of the current page. Must be the same as the author slug!
        $page_slug = basename(get_permalink());
        $user = get_user_by('slug', $page_slug);
        $the_query = new WP_Query( 'author=' . $user->ID . '&posts_per_page=5');
        while ( $the_query->have_posts() ) : $the_query->the_post();
        ?>
    
          <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
      <?php endwhile;  wp_reset_postdata(); ?>
    </ul>
    Thread Starter vectyr

    (@vectyr)

    Hey man, total kudos, that code is PERFECT, thank you so much for your time! This is exactly what I was looking for and works like a dream. Sorry it took me so long to get back with you, I had a crazy weekend!

    You’re welcome! ??
    Have fun with it and always take care of the identical slugs ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Showing Posts from an Author on a Page’ is closed to new replies.