PHP的the_content()函数wordpress错误

时间:2015-04-09 10:19:34

标签: php wordpress

我正在尝试创建一个函数,允许我使用the_content字段中更多的<!--more-->标记在wordpress中SPLIT posts。 但是,我不知道我在做什么,似乎弄得一团糟

在我的functions.php中,我有以下代码。

function split_content() {

    global $more;
    $more = true;
    $content = preg_split('/<span id="more-d+"></span>/i', get_the_content('more'));
    for($c = 0, $csize = count($content); $c < $csize; $c++) {
        $content[$c] = apply_filters('the_content', $content[$c]);
    }
    return $content;
}

在我的homepage.php中,我已将the_content替换为以下函数

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

        <?php
        $content = split_content();
        echo '<div>', array($content[0]), '</div>';
        ?>

        <?php endwhile; endif; ?
?>

此系统提供2个错误:

  

警告:preg_split()需要至少2个参数,给出1   C:\ MAMP \ htdocs中\ WordPress的\可湿性粉剂内容\主题\测试\ WP-香草\的functions.php   在第125行

     

注意:数组转换为字符串   C:\ MAMP \ htdocs中\ WordPress的\可湿性粉剂内容\主题\测试\ WP-香草\页面homepage.php   在第41行

有人可以帮忙吗?我尝试了各种组合。

2 个答案:

答案 0 :(得分:1)

也许你需要使用这个函数get_extended() WP Codex

它返回值

(数组)     发布之前(&#39;主要&#39;)和之后(&#39;延伸&#39;)。

答案 1 :(得分:0)

你也可以尝试这样的事情:

$morestring = '<!--more-->';
$explode_content = explode( $morestring, $post->post_content );
$content_before = apply_filters( 'the_content', $explode_content[0] );
$content_after = apply_filters( 'the_content', $explode_content[1] );

希望它在某种程度上有所帮助。