• 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 , TitleC

    Is 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>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mklappen

    (@mklappen)

    Of course the formatting of the HTML when I post here doesn’t show up how I see it, but the while loop outputs each “the_title()” on a separate line and there are extra spaces that’s causing more whitespace around my commas…

    Thanks in advance for any help.

    Thread Starter mklappen

    (@mklappen)

    updated with “code” brackets so now it looks how I see it in source

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘While Loop extra spaces in html output’ is closed to new replies.