WordPress.org

Ready to get started?Download WordPress

Forums

Adding author to recent posts list? (2 posts)

  1. lhk
    Member
    Posted 8 years ago #

    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?

  2. lhk
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic