我通过创建两个要拆分的函数来解决这个问题the_content()
在前后函数中:
class MyClass
{
/**
* Echo the content before the <!--more--> tag
*/
public static function getContentBeforeMore()
{
global $more;
$more = false;
the_content(false);
$more = true;
}
/**
* Echo the content after the <!--more--> tag
*/
public static function getContentAfterMore($removeMoreTag = true)
{
$content = get_the_content(null, true);
$content = apply_filters( \'the_content\', $content );
$content = str_replace( \']]>\', \']]>\', $content );
// Remove the empty paragraph with the <span id="more-.."></span>-tag:
if($removeMoreTag)
{
$content = preg_replace(\'/<p><span id="more-\\d+"><\\/span><\\/p>/m\', \'\', $content);
}
echo $content;
}
}
在模板中,可以这样使用:
<p class="intro"><?php MyClass::getContentBeforeMore(); ?></p>
... some other styling, like date or something ...
<?php MyClass::getContentAfterMore(); ?>