Support » Fixing WordPress » Adding author to recent posts list?

  • Hi,

    I display recent posts by this piece of code:

    <!-- item -->
    <div class="item" id="previously">
    <h2>More Recent Posts</h2>
    <div class="item-ctnt">
    <ul>
    <?php
    $posts = get_posts('numberposts=15&offset=2');
    foreach($posts as $post) :
    ?>
    <li><span class="sp-date">
    <?php the_time('M j'); ?>
    : </span> <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?>
    </a></li>
    <?php endforeach; ?>
    </ul>
    </div>
    </div>
    <!-- item -->

    I would Like to add “by authornickname” to each line.

    This code:

    <!-- item -->
    <div class="item" id="previously">
    <h2>More Recent Posts</h2>
    <div class="item-ctnt">
    <ul>
    <?php
    $posts = get_posts('numberposts=15&offset=2');
    foreach($posts as $post) :
    ?>
    <li><span class="sp-date">
    <?php the_time('M j'); ?>
    : </span> <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?>
    </a> by <?php the_author_nickname(); ?></li>
    <?php endforeach; ?>
    </ul>
    </div>
    </div>
    <!-- item -->

    does not do the trick, it displays one and the same author name for all posts, not the name of the author who wrote the post.

    Quick help anyone?

Viewing 1 replies (of 1 total)
  • Ok, found it myself:

    <!-- item -->
    <div class="item" id="previously">
    <h2>More Recent Posts</h2>
    <div class="item-ctnt">
    <ul>
    <?php
    $posts = get_posts('numberposts=15&offset=2');
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    <li><span class="sp-date">
    <?php the_time('M d'); ?>
    : </span> <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?>
    </a> by <?php the_author_nickname(); ?></li>
    <?php endforeach; ?>
    </ul>
    </div>
    </div>
    <!-- item -->

Viewing 1 replies (of 1 total)
  • The topic ‘Adding author to recent posts list?’ is closed to new replies.