0

I have the following code to list my authors in my sidebar except for the admin account. It works very well in function. However, it prints an extra paragraph element that includes two ancor tags with link of both of the previous and current author's latest post seperated with a break element.

Could you please help me on how to eliminate those paragraphs at all.

The code:

    $authors=get_users();
$i=0;
//get all users list
foreach($authors as $author){
    $authorList[$i]['id']=$author->data->ID;
    $authorList[$i]['name']=$author->data->display_name;
    $i++;
}
?>
<div class="sidebar-authors-custom better-slider" id="sidebar-authors-custom">
    <?php 
    foreach($authorList as $author){
        $args=array(
                'showposts'=>1,
                'author'=>$author['id'],
                'caller_get_posts'=>1
               );
        $query = new WP_Query($args);
        if($query->have_posts() ) {
            while ($query->have_posts()){
                $query->the_post();
    ?>
    <?php if($author['id'] != 1){ ?>
      <a href="<?php echo get_permalink(); ?>"><div class="author">
            <div class="profile-img">
            <?php echo get_avatar( $author['id'] , 80); ?>
            </div><div class="profile-info"><span class="name"><?php echo $author['name']; ?></span>
            <span class="title"><?php echo get_the_title(); ?></span></div></div></a>
      <?php }}}} ?></div>

Here is the generated HTML output:

<div>
 <a href="#">
  <div class="author">
   <div class="profile-img">
    <img class="avatar" height="80" width="80" src="#">                  
   </div>
  <div class="profile-info">
   <span class="name">Author Name</span><br>
   <span class="title">Post Title</span>
  </div>
 </div>
</a>
</div>

<div>
 <p style="width: 100%; display: inline-block;">
  <a href="LINK OF PREVIOUS POST"></a><br>
  <a href="LINK OF CURRENT POST" tabindex="-1"></a>
 </p>
</div>

Then it loops again. I don't know why the second div is even generated.

  • Can you provide a snippet of the HTML output. – Drupalizeme Jul 9 '18 at 11:36
  • @Drupalizeme I added the HTML output at the end of the question – Özgür Polat Jul 9 '18 at 19:56
  • I think the issue is not in the code you posted but in the code after that lines. For example, maybe there is a call to previous_post_link or next_post_link or maybe there is an include of another function that renders the elements. To be honest there is lots of possibilities as there are some cases where the output is first "cached" and then returned ob_start(). – Drupalizeme Jul 10 '18 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.