Find and print first li tag entry from WordPress post in custom excerpt?
-
I want to create a custom excerpt for an education website. It has posts that contains listing. I want to print the first child of ul and a first child of ol tag from the post.
Currently, I have the following code that can print only the first paragraph.
function wpden_excerpt() { global $post; $output = get_the_content(); $wanted_number_of_paragraph = 1; $tmp = explode ('</p>', $output); for ($i = 0; $i < $wanted_number_of_paragraph; ++$i) { if (isset($tmp[$i]) && $tmp[$i] != '') { $tmp_to_add[$i] = $tmp[$i]; } } $output = implode('</p>', $tmp_to_add) . '</p>'; echo $output; }
<?php wpden_excerpt(); ?>
HTML
<p>Once in a blue moon</p> <p>Meaning</p> <ul> <li>not very often</li> <li>rarely</li> <li>once after a long time</li> </ul> <p>Examples</p> <ol> <li>My sister lives in Alaska, so I only see her once in a blue moon.</li> <li>Once in a blue moon, there's an issue I can't resolve.</li> <li>That company puts on a good performance only once in a blue moon.</li> </ol>
Now I want to print something like that:
<p> <b>Meaning:</b> not very often<br /> <!-- Content from first <li> of first <ul> --> <b>Example:</b> My sister lives in Alaska, so I only see her once in a blue moon. <!-- Content from first <li> of first <ol> --> </p>
I’ve tried a lot, but I am not getting succeeded. Plz help!
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Find and print first li tag entry from WordPress post in custom excerpt?’ is closed to new replies.