0

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.

1

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>';

Your Answer

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

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