|
|
发表于 2023-7-13 23:18:02
|
显示全部楼层
|
The warning message "Warning: A non-numeric value encountered in" is caused by the line of code $commentcount = intval($cpp) * intval($page);. The intval() function is used to convert a string to an integer. However, the value of $page may not be an integer. For example, if the user is on the first page of comments, the value of $page will be 0. This will cause the intval() function to fail, and the warning message will be displayed.
To fix this error, you need to check the value of $page before calling the intval() function. If the value of $page is not an integer, you can convert it to an integer using the following code:
PHP
if (!is_numeric($page)) {
$page = 0;
}
请谨慎使用代码。了解详情
Once you have converted the value of $page to an integer, you can call the intval() function without any errors.
Here is the corrected code:
PHP
function devecomment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
global $commentcount;
if (!$commentcount) {
$page = get_query_var('cpage') - 1;
if (!is_numeric($page)) {
$page = 0;
}
$cpp = get_option('comments_per_page');
$commentcount = intval($cpp) * intval($page);
}
}
请谨慎使用代码。了解详情
This code will now correctly convert the value of $page to an integer, and the warning message will no longer be displayed. |
|