Forums

Author List With Latest Post & Image On The Sidebar (6 posts)

  1. korhan
    Member
    Posted 2 years ago #

    Ok, I know the code to display authors with latest post and image on the sidebar as below. I now need to:

    1)- exclude admin,
    2)- display 5 authors (most recent 5 authors who published a post)

    <?php
    //get all users, iterate through users, query for one post for the user,
    //if there is a post then display the post title, author, content info
    $blogusers = get_users_of_blog();
    
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $args = array(
              'author' => $bloguser->user_id,
    	  'showposts' => 1,
    	  'caller_get_posts' => 1,
        );
    
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <div style="border-top:1px solid #bababa; margin:0">
    <?php echo get_avatar( get_the_author_email(), '80' ); ?>
    
    <h4 style="padding-top:10px;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br /><small><?php the_author_posts_link(); ?> </small></h4>
    		<?php
            the_excerpt();
    		?>
            <p class="more-link"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" style="color: rgb(157, 20, 20); font-weight: bold;"><?php _e('Read', 'news'); ?></a> | Comments (<?php comments_number('', '1', '%'); ?>)</p>
            </div>
     <?     endwhile;
        }
    
      }
    }
    
    ?>
  2. korhan
    Member
    Posted 2 years ago #

    Can someone help please?

  3. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try adding:
    $excl_authors = array('1', '5', '7', '8');
    after:
    $blogusers = get_users_of_blog();
    The array should hold a list of author/users ids that you want to exclude. Then just before div style="border-top:1px solid #bababa; margin:0">, add:
    <?php if( !in_array( $post->post_author, $excl_authors ) :?>
    Finally change <? endwhile; to <?php endif;endwhile;?> and see how that works out.

  4. korhan
    Member
    Posted 2 years ago #

    Thanks esmi. I did as you said but got:

    Parse error: syntax error, unexpected ':'

    When you say this:

    <?php if( !in_array( $post->post_author, $excl_authors ) :?>

    Do you mean this:

    <?php if( !in_array( $post->post_author, $excl_authors ) ) :?>

    or this:

    <?php if( !in_array( $post->post_author, $excl_authors ) ) ;?>

    I tried all variations above but then got error with your final change "endif;endwhile".

    Also this code above does not limit to the most recent 5 posts. I want to limit to 5 recent posts, and 1 per/author on the sidebar.

    PS- I use 2.91 version of WP.

  5. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Sorry...sorry.. It should have been:
    <?php if( !in_array( $post->post_author, $excl_authors ) ) :?>

  6. ziguline
    Member
    Posted 2 years ago #

    Hi korhan,

    could you please help me suggesting the code to list randomly five authors of my blog with a thumb of their photo and the 3 latest posts published by each of them.. I'm tryng to do something like that (look at the link)

    http://www.ziguline.com/example.jpg

    Thank you.

    Dimitri

Topic Closed

This topic has been closed to new replies.

About this Topic