从帖子中定位和发布块引用

My Wordpress site's index.php has a div which posts the title, category, and featured image of the posts.

index.php HTML

<div>
    <h1><?php the_title(); ?></h1>
    <h3><?php the_category(' '); ?></h3>
</div>

I have a single.php which brings in and puts the content of the post

single.php HTML

<div>
    <?php the_content(); ?>
</div>  

I want to bring a section of the_content of the post into my index.php (for example anything in the 'block quote' tag)

EX.

 <div>
    <h1><?php the_title(); ?></h1>

    ... content from block quote    

    <h3><?php the_category(' '); ?></h3>
</div>

You can retrieve the content with get_the_content(), then check if there's a blockquote and, if so, echo it:

// get the content
$content = get_the_content();
// check and retrieve blockquote
if(preg_match('~<blockquote>([\s\S]+?)</blockquote>~', $content, $matches))
    // output blockquote
    echo $matches[1];

You can parse data from HTML tags using the DOM module. This is an excellent guide to doing so.

You can also use REGEX (Somebody has shown this already so I removed the link I was gonna show)

Another option is to parse it yourself with explode etc. Like so:

//Get the content
$content = the_content();

//Explode to separate the first tags
$blockquotes = explode("<blockquote>", $content);

//Data array to use
$data = array();

//For each of these
foreach($blockquotes as $x){
    //Find the location of </blockquote>
    $end_loc = strpos($x, "</blockquote>");

    //Remove everything after by only taking everything before it
    $temp = substr($x, 0, $end_loc);

    //Add it to the array
    $data[] = $temp;
}

//Data now contains all of the data, do as you please with it
var_dump($data);