【发布时间】:2021-03-23 19:23:03
【问题描述】:
你能告诉我这段来自 wordpress 的代码有什么问题吗
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>Continue Reading »</a>";
echo $excerpt;
}
当我使用它时,它会显示:
警告:在 C:\xampp\htdocs\learningwp\wp-content\themes\mytheme\functions.php 中使用未定义常量 readmore - 假定为“readmore”(这将在 PHP 的未来版本中引发错误)第 71 行。
我该如何解决这个问题?
【问题讨论】:
-
您能描述一下这段代码的用途吗?该错误显然表明您正在尝试使用名为 $readmore 的变量,但在您的代码中您缺少 $ 符号,因此它试图将其视为未定义的常量“readmore”。
标签: php html wordpress type-conversion wordpress-theming