WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. guffia
    Member
    Posted 7 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">
    <?php
    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));
    endif;
    ?>
    
    <?php rewind_posts(); ?>
    
    <?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <ul><li>All posts by <?php echo $curauth->nickname; ?></li>
          <h3>
        <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
    Member
    Posted 7 years ago #

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

    <?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>
    <?php
    }
     endwhile;
    ?>
  3. sadish
    Member
    Posted 7 years ago #

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

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

    lets see if it works

    Sadish

Topic Closed

This topic has been closed to new replies.

About this Topic