简体   繁体   English

将段落标签放在内容段落上

[英]putting paragraph tags on content paragraphs

Im trying to put paragraph text around the paragraphs. 我试图将段落文本放在段落周围。 This code pulls out the blockquotes from my Wordpress post and outputs everything else 这段代码从我的Wordpress帖子中提取出了引号,并输出了其他所有内容

html html

        <?php
            $block2 = get_the_content();
            $block2 = preg_replace('~<blockquote>([\s\S]+?)</blockquote>~', '', $block2);
            echo '<p>'.$block2.'</p>';
        ?>

But it only puts < p > tags around the fist paragraph and not the others 但这只会将<p>标记放在第一个段落的周围,而不是其他

If I've understood this correctly, you could try splitting $block2 by newlines, looping through the resulting array and wrapping each element of the array in <p> tags as you have done. 如果我正确理解了这一点,则可以尝试用换行符分隔$block2 ,遍历结果数组并将数组中的每个元素包装在<p>标记中。

Currently, your code wraps the entire content of $block2 in <p> tags, where I assume you wanted it to wrap the sections separated by newlines. 当前,您的代码将$block2的全部内容包装在<p>标记中,我假设您希望它包装用换行符分隔的部分。

Example (I don't remember the exact syntax for PHP - sorry): 示例(我不记得PHP的确切语法了-对不起):

$split_block = split($block2, '\n');
for ($i in $split_block) {
    $split_block[$i] = '<p>'.$split_block[$i].'</p>';
}
echo $split_block;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM