WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Posts By Author (8 posts)

  1. jackosh
    Member
    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:

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

    So that it only gets posts from a specific author?

  2. KatGirl
    Member
    Posted 7 years ago #

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

    wordpress.org/support/topic/67178?replies=1

  3. jackosh
    Member
    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
    Member
    Posted 7 years ago #

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

  5. jackosh
    Member
    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!


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

  6. Kafkaesqui

    Posted 7 years ago #

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

  7. jackosh
    Member
    Posted 7 years ago #

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

  8. bahera
    Member
    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

Tags

No tags yet.