I am trying to create two functions, one that catches the first paragraph of some content, and one that catches the rest, but I have hit a bit of a conundrum.
I have this in my single.php:
<div class='the_content'>
<?php the_content(); ?>
</div>
which produces:
<div class="the_content">
<p>The content .....</p>
<p>The content .....</p>
<p>The content .....</p>
</div>
each paragraph all nicely wrapped in a <p>
tag. I assumed that I could simple break the explode()
the content based on the string </p>
, theoretically splitting the content into paragraphs, but all the content is in the first resulting array element. I investigated, and there are no <p>
tags in either the HTML edit, or indeed the database entry. Both look like:
The Content .....
The Content .....
The Content .....
Note:Line breaks present, but not <p>
tags.
Where does Wordpress add the <p>
back in? How does it find the line breaks and how can I hook a function into that?
FYI
Here is the function that fails, based closely on the the_content()
function:
function get_first_paragraph(){
$content = $firstcontent = get_the_content();
$content = str_replace(']]>', ']]>', $content);
$content = explode('</p>',$content);
return $content[0];
}