[resolved] Listing writings by the author of post currently being viewed (3 posts)

  1. guffia
    Posted 9 years ago #

    So, here is what I would like to do: when a reader clicks on a post title to read the whole thing, in that template there will be a div where all the posts by the author of the current post will be listed. Right now I'm trying to technique discussed here: http://codex.wordpress.org/Author_Templates but it's not working. It's only listing the current post. Here's what my code currently looks like:

    <div id="sidebar">
    if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($author_name); // NOTE: 2.0 bug requires get_userdatabylogin(get_the_author_login());
    else :
    $curauth = get_userdata(intval($author));
    <?php rewind_posts(); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <ul><li>All posts by <?php echo $curauth->nickname; ?></li>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
          <small><?php the_time('F jS, Y') ?> </small>
       <?php endwhile; ?>
       <?php else : ?>
          <p>No posts by this author</p>
       <?php endif; ?>

    As I said, I want it to list all the posts by the author whose post you are currently reading, but right now it's only listing the current one.

  2. MichaelH
    Posted 9 years ago #

    Using the WordPress Default 1.6 theme to test, placed this code right after the <?php comments_template(); ?> line in single.php:

    $do_not_duplicate = $post->ID;
    $my_query = new WP_Query('author=' . get_the_author_ID() );
    while ($my_query->have_posts()) : $my_query->the_post();
    if( $post->ID != $do_not_duplicate ) { ?>
    <h2><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
  3. sadish
    Posted 9 years ago #

    just after the rewind_posts() call. try adding this.

    <?php query_posts('author_name='.$curauth->nickname); ?>

    lets see if it works


Topic Closed

This topic has been closed to new replies.

About this Topic