在这种情况下,请使用<! - more - >之前的内容

时间:2014-04-23 16:02:11

标签: wordpress

我想在<!--more--> - 标记之前回复内容,而不是在250个字符后删除内容。主题不使用the_content。     

    $content_of_post = get_post($get_post_id);
    $content = $content_of_post->post_content;
    $content = apply_filters('the_content', $content); 
    echo substr($content, 0, "250");
?>

1 个答案:

答案 0 :(得分:1)

您可以通过strpos函数将文本截断到<!--more-->,即:

substr($content, 0, strpos($content, '<!--more-->'));

试试这个:

<?php
$content_of_post = get_post($get_post_id);
$content = $content_of_post->post_content;
$content = substr($content, 0, strpos($content, '<!--more-->'));
echo apply_filters('the_content', $content);
?>