While Loop extra spaces in html output
-
I have a while loop that is giving me some formatting issues when it renders in browser. I am trying to list some posts (comma separated) in a paragraph tag.
$postCount = 0; echo '<p>'; while ( $platforms->have_posts() ) : $platforms->the_post();?> <a href="<?php the_permalink()?>" title="<?php the_title();?>"><?php trim(the_title());?></a> <?php ++$postCount; if ($postCount < $platforms->found_posts) { echo ", "; } endwhile; echo '</p>';However when I look at the HTML source, there’s all this extra white space that is adding an extra space in the browser view.
<p> <a href="mysite" title="TitleA">TitleA</a> , <a href="mysite" title="TitleB">TitleB</a> , <a href="mysite" title="TitleC">TitleC</a> </p>So instead of my format looking like this: TitleA, TitleB, TitleC
There is extra space before the comma.
TitleA , TitleB , TitleCIs there something in wordpress php that is causing each Title link to go to a separate line? I would expect the source to look like this
<p><a href="mysite" title="TitleA">TitleA</a>, <a href="mysite" title="TitleB">TitleB</a>, <a href="mysite" title="TitleC">TitleC</a></p>
The topic ‘While Loop extra spaces in html output’ is closed to new replies.