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:

//get all users list
foreach($authors as $author){
<div class="sidebar-authors-custom better-slider" id="sidebar-authors-custom">
    foreach($authorList as $author){
        $query = new WP_Query($args);
        if($query->have_posts() ) {
            while ($query->have_posts()){
    <?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:

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

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

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.