Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this php code below for displaying the post from the specific categories.

<ul id="sliderx">
<?php query_posts('category_name=slideshow&showposts=10');
while (have_posts()) : the_post();
echo "<li>".the_content()."</li>";
endwhile;?>
</ul>

as you can see, it display those post in the category slideshow and the structure of that should be this.

<ul id="sliderx">
<li>the post 1</li>
<li>the post 2</li>
<li>the post 3</li>
</ul>

but the output that is generated is this.

<ul id="sliderx">
<p>three</p>
<li></li><p>two</p>
<li></li><p>one</p>
<li></li>
</ul>

and the generated structure should not look like that and it looks nasty at all, so im having a problem on this on how to display it properly like to display into this structure.

<ul id="sliderx">
<li>the post 1</li>
<li>the post 2</li>
<li>the post 3</li>
</ul>

So Im wondering if there's someone who could tell me how to fix this.

Im open into any suggestions, recommendations and suggestions. Thank you.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

That happens because the_content() contains already an echo. PHP tries to create the string before it sends it to the echo command. While the string is evaluated the content will be printed already. Then echo gets what was not yet printed: the li tags.

So the simple fix is:

echo '<li>';
the_content();
echo '</li>';
share|improve this answer
    
brilliant. Works like charm, thank you person. :) –  Juliver Galleto Oct 7 '12 at 21:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.