• Resolved jackosh

    (@jackosh)


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

    <?php
    $posts = get_posts('numberposts=5');
    foreach ($posts as $post) :
    setup_postdata($post);
    ?>

    So that it only gets posts from a specific author?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can try this instead. I use it and it works brilliantly.

    www.ads-software.com/support/topic/67178?replies=1

    Thread Starter jackosh

    (@jackosh)

    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!

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

    Thread Starter jackosh

    (@jackosh)

    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!


    <?php
    $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=\"";
    the_permalink();
    echo "\">";
    the_title();
    echo "</li>
    ";
    $count++;
    }
    endforeach; ?>

    A little simpler solution:

    <?php
    $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; ?>

    Thread Starter jackosh

    (@jackosh)

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

    bahera

    (@bahera)

    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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Posts By Author’ is closed to new replies.