Ready to get started?Download WordPress


[resolved] Posts By Author (8 posts)

  1. jackosh
    Posted 7 years ago #

    I've been looking all over for this, and can't seem to find it. Is there a way to change this code:

    $posts = get_posts('numberposts=5');
    foreach ($posts as $post) :

    So that it only gets posts from a specific author?

  2. KatGirl
    Posted 7 years ago #

    You can try this instead. I use it and it works brilliantly.


  3. jackosh
    Posted 7 years ago #

    yeah, I saw that, BUT I am trying to implement this is the sidebar or a page, and not at the bottom of a post!

  4. KatGirl
    Posted 7 years ago #

    I use it in both my sidebar and page... all you need do is read his offerings

  5. jackosh
    Posted 7 years ago #

    Thanks! I'm looking for something a lot more light weight!

    This seems to be working (for anyone else who needs it).. found it somewhere in the forums!

    $count = 0 ;
    $authorID = get_the_author_ID() ;
    $posts = get_posts('numberposts=5&&orderby=post_date');
    foreach ($posts as $post) : start_wp();
    if($post->post_author==$authorID && $count < "10"){
    echo "
    <li><a href=\"";
    echo "\">";
    echo "</li>
    endforeach; ?>

  6. Kafkaesqui

    Posted 7 years ago #

    A little simpler solution:

    $authposts = new WP_Query('author=' . get_the_author_ID() . '&showposts=5');
    while($authposts->have_posts()) : $authposts->the_post();
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></li>
    <?php endwhile; ?>

  7. jackosh
    Posted 7 years ago #

    works real well, thanks! for anyone else, don't forget to and the link after the permalink!

  8. bahera
    Posted 7 years ago #

    I thought this was just what I was looking for (have been scouring forums and docs all night) It works fab in the sidebar on my author pages, but obviously not when viewing main page or category pages. I've tried using conditional tags to vary the sidebar content, but I can't get it to work. What am I doing wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.