What is wrong with this php loop?
Posted
by
Mark R
on Stack Overflow
See other posts from Stack Overflow
or by Mark R
Published on 2012-06-07T10:35:37Z
Indexed on
2012/06/07
10:40 UTC
Read the original article
Hit count: 160
I made a loop but it doesn't work.
here's what I did:
<?php if(is_tree('4')) { ?>
<?php
$show_after_p = 2;
$content = apply_filters('the_content', $post->post_content);
if(substr_count($content, '<p>') > $show_after_p)
{
$contents = explode("</p>", $content);
$p_count = 1;
foreach($contents as $content)
{
echo $content;
if($p_count == $show_after_p)
{
?>
YOUR AD CODE GOES HERE
< ?
}
echo "</p>";
$p_count++;
}
}
?>
<?php else : ?>
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php endif; } ?>
I need to make it work but don't know how. I'm guessing it's a simple syntax error I'm not seeing?
© Stack Overflow or respective owner