I want to get the first blockquote from the post (even if the user writes only one, or more than one) in the Quote Post Format, in order to show it in the archive Loop. For example:

$quote = has_post_format( 'quote' );
if ( $quote ) {
    if ( *the post has no quotes* ){
        // Don't show anything
    } else {
        // Show the blockquote from the post (if there's only one),
        // or the first one (if there are more than 1)
    }
}

Is there something like this?

2 Answers
2

I finally found a solution that works. In case you need it, here it is:

<?php
if (has_post_format('quote', $post->ID)) {
    $content = trim(get_the_content());
    // Take the first quote from the content
    $quote_string = extract_from_string('<blockquote>', '</blockquote>', $content);
    // Make sure there's a quote on the content
    if (!$quote_string == "") {
         // Get the first quote and show it on the Loop
         echo $quote_string;
    } else {
         // If not, show nothing
    }
}
?>

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *