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];
}
The paragraphs are done by the
wpautop()
function, hooked tothe_content
,the_excerpt()
&comment_text
as well as'term_description'
for taxonomies.The plugin linked by @javipas does an enormous effort to just add this, but it’s a good example (+1). You can (modify it a little and) take the following part out of it:
Notes:
If I have understand you, what you want is permalinks for each paragraph? The known blogger Dave Winer wrote about this a year ago, and there’s a plugin called WinerLinks that puts a ‘#’ after each paragraph, that makes that paragraph linkable.
I hope it works for you.
afaik, by applying the ‘the_content’ filter.
possible examples for your functions:
and: