首页 文章

PHP的the_content()函数wordpress错误

提问于
浏览
0

我正在尝试创建一个函数,允许我使用 posts 字段中的更多 <!--more--> 标记在wordpress中SPLIT the_content . 但是,我并没有这样做,而且似乎弄得一团糟

在我的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个参数,在第125行的C:\ MAMP \ htdocs \ wordpress \ wp-content \ themes \ Test \ wp-vanilla \ functions.php中给出1注意:C中的数组转换为字符串第41行:\ MAMP \ htdocs \ wordpress \ wp-content \ themes \ Test \ wp-vanilla \ page-homepage.php

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

2 回答

  • 0

    也许你需要使用这个功能get_extended() WP Codex

    它返回值

    (数组)发布之前('main')和之后('extended') .

  • 1

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

    $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] );
    

    希望它能在某种程度上帮助你 .

相关问题