【问题标题】:PHP the_content() function wordpress errorsPHP the_content() 函数 wordpress 错误
【发布时间】:2015-06-14 15:50:18
【问题描述】:

我正在尝试创建一个函数,允许我使用 posts 字段中的更多 <!--more--> 标记在 wordpress 中拆分 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; ?
?>

这个系统有两个错误:

警告:preg_split() 至少需要 2 个参数,其中 1 个在 C:\MAMP\htdocs\wordpress\wp-content\themes\Test\wp-vanilla\functions.php 在第 125 行

注意:数组到字符串的转换 C:\MAMP\htdocs\wordpress\wp-content\themes\Test\wp-vanilla\page-homepage.php 第 41 行

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

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

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

    返回值

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

    【讨论】:

      【解决方案2】:

      你也可以试试这样的:

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

      希望对你有所帮助。

      【讨论】:

      • 感谢 jenis,这确实有帮助.... 上面的代码是否放在 functions.php 中?我需要在我的 index.php 中放置什么,即我是否希望显示内容?
      猜你喜欢
      • 2016-03-04
      • 1970-01-01
      • 2019-07-06
      • 2015-05-09
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多