Hello I am trying to achieve this output: IF PARAGRAPH IS AFTER PARAGRAPH5 // EXECUTE CODE Can it be done? Thanks
I'm guessing there is a clear divide between paragraphs, perhaps 2 "\n" occur or something similar? Explode by the divider, then use a loop and if the current loop is greater than 5, run extra code, e.g. echo an image. Dan P.s. be less vague next time, my answer my be completely wrong - but it's hard without much detail.
OK - I should add that this is for a WordPress blog and I know a bit of PHP but I'm no expert. When you say explode, divider, and loop, it baffles me.
if your paragraphs are in an array or being taken from a database maybe: $paragraphs = array('p1','p2','p3','p4','p5'); //Array should contain your paragraphs for($i=0; $i<count($paragraphs); $i++){ echo $paragraph[$i]; if($i == 5){ echo '<br /> -graphic code goes here'; } } PHP:
This is bascially what I'm saying above, (www.php.net/explode is just a way of getting a string into an array.) and lui has used a suitable loop for showing the text. Although always assign count($paragraphs) to a variable before looping, or it will be ran every loop. Dan p.s. and divider just means something that divides (i.e. goes in between) the paragraphs.
I don't think WordPress stores paragraphs (I can't find the table). Does that mean it won't work? Thanks.
No, you could write an extremely basic plugin, which would then have a hook added to the text, which could do this for you. Dan
Yeah I did it this way. It worked. Thanks. I have to generate the code by clicking a button for each post - but that also gives me more control over ad optimization so I think it's fine.