【发布时间】: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 行
有人可以帮忙吗?我尝试了各种组合。
【问题讨论】: