Forums

[resolved] Mini-loop and author (2 posts)

  1. nsdjc
    Member
    Posted 4 years ago #

    I've been using the mini-loop to pull a sort of rss feed into my static home page. However, my blog has multiple authors and I'd like to integrate that into the mini-loop while maintaining the formatting in the current list. Here's the code I've been using:

    <?php
    $how_many=3; //How many posts do you want to show
    require_once("blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
    <ul><?
    $news=$wpdb->get_results("SELECT <code>ID</code>,<code>post_title</code>,<code>post_date</code>,<code>post_author</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>= \"publish\" ORDER BY ID DESC LIMIT ".$how_many);
    foreach($news as $np){
      echo '
        <li><a href="'.get_permalink($np->ID).'">'.$np->post_title.'</a>
        <br><em>'.date('l, F jS Y', strtotime($np->post_date)).'</em></li>';
    } ?></ul>

    Is there any way I can add the author name while maintaining the formatting style I have now?

  2. nsdjc
    Member
    Posted 4 years ago #

    Nevermind, I just used a different set of code:

    <?php $posts = get_posts( "numberposts=3" ); ?>
    <?php if( $posts ) : ?>
    <ul>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
    <li>
    <a href=<?php the_permalink() ?>>
    <?php the_title(); ?>
    </a><br><em>by <?php the_author(); ?> on <?php the_time('F j, Y');?></em>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic