php - 在 wordpress 的开始或结束页面中出现自定义分页错误
问题描述
现在我在 wordpress 上做自定义模板。我制作了自定义分页。我做了很多硬代码来进行分页。如果第二页或第三页上的分页,一切都很好。但是在开始页码或结束页码时会出现错误。
这是代码
function list_pagination($Posts) {
$big = 999999999;
$paged = paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'prev_next' => false,
'type' => 'array',
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => '',
'total' => $Posts->max_num_pages
));
if ( ! empty( $paged ) ) :
echo '<ul class="pager_list">';
$no = 1;
foreach ( $paged as $page_link ) :
if ( strpos( $page_link, 'current' ) !== false ) { $active = ' active'; }else{ $active = "";}
$anchor = new SimpleXMLElement($page_link);
echo '<li class="pager_item"><a href="'.$anchor['href'].'" class="pager_link'.$active.'"><span>'.$no.'</span></a></li>';
$no++;
endforeach;
echo '</ul>';
endif;
}
当页码在页码开始或页码结束时。它显示这样的错误
<b>Warning</b>: SimpleXMLElement::__construct(): Entity: line 1: parser error : Entity 'hellip' not defined in <b>C:\xampp\htdocs\wordpress\wp-content\themes\templateme\functions.php</b> on line <b>23</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::__construct(): <span class="page-numbers dots">&hellip;</span> in <b>C:\xampp\htdocs\wordpress\wp-content\themes\templateme\functions.php</b> on line <b>23</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::__construct(): ^ in <b>C:\xampp\htdocs\wordpress\wp-content\themes\templateme\functions.php</b> on line <b>23</b><br />
<br />
<b>Fatal error</b>: Uncaught Exception: String could not be parsed as XML in C:\xampp\htdocs\wordpress\wp-content\themes\templateme\functions.php:23
Stack trace:
#0 C:\xampp\htdocs\wordpress\wp-content\themes\templateme\functions.php(23): SimpleXMLElement->__construct('<span class="pa...')
#1 C:\xampp\htdocs\wordpress\wp-content\themes\templateme\column.php(143): list_pagination(Object(WP_Query))
#2 C:\xampp\htdocs\wordpress\wp-includes\template-loader.php(98): include('C:\\xampp\\htdocs...')
#3 C:\xampp\htdocs\wordpress\wp-blog-header.php(19): require_once('C:\\xampp\\htdocs...')
#4 C:\xampp\htdocs\wordpress\index.php(17): require('C:\\xampp\\htdocs...')
#5 {main}
thrown in <b>C:\xampp\htdocs\wordpress\wp-content\themes\templateme\functions.php</b> on line <b>23</b><br />
解决方案
推荐阅读
- google-apps-script - Google 脚本编辑器 - 找不到方法 formatDate(object,string,string)
- c - 如何在编译时初始化结构成员,具体取决于数组中先前定义的条目的值
- node.js - ECONNRESET error while fetching an URL in node.js
- mysql - 使用变量并重用它时 SELECT 语句无法正确显示数据
- sql - 如何在 oracle 中同时使用双重分组和求和语句
- android - 有没有办法检查 LOCAL_SHARED_LIBRARIES 是否成功集成到 android 应用程序中?
- python - Tensorflow:如何使用 tensorflow 操作从给定的字符串列表中选择一个随机字符串
- python - 类型错误:get_first_name() 缺少 1 个必需的位置参数:Python 中的“自我”
- c++ - 尝试使用 CMake 和 MinGW64 构建时出现多个重新定义错误
- installation - 在 Inno Setup 中转换 CurrentFilename 返回的 {constants}