WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show latest posts by all authors (4 posts)

  1. callender
    Member
    Posted 3 years ago #

    Hi,

    I want to show the latest post (1 only) from all the authors on a wordpress site.

    How do I do this? I have written a custom template for this feature, I have to create my own loop I expect.

    Any help to understand how this is done would be appreciated!

    Jim C

  2. MichaelH
    Member
    Posted 3 years ago #

    One example

    <?php
    //displays all users with their avatar and one post (title)
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $user = get_userdata($bloguser->user_id);
        echo '<p>User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname . '</p>';
        echo get_avatar( $user->ID, 46 );
        $args=array(
          'author' => $user->ID,
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 1,
          'caller_get_posts'=> 1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          //echo 'List of Posts for ' . user->user_firstname . ' ' . $user->user_lastname;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php
          endwhile;
        }
      wp_reset_query();  // Restore global post data stomped by the_post().
      }
    }
    ?>
  3. callender
    Member
    Posted 3 years ago #

    I used this example in the end, thanks though

    http://wpsplash.com/how-to-create-a-wordpress-authors-page/

  4. chavo
    Member
    Posted 3 years ago #

    Hi. I was lookig for a while a solution similar to this one all over the internet and the forum support but I can't find one solution that fits what I need. Is there a way to limit the post to X amount of authors? I mean, I need to show the latest 4 post published with:

    - Post title and link
    - Author avatar
    - Author extra profile info (I add an extra profile field labeled as "sport").

    Any solution? Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic