首页 > 解决方案 > 在 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(): &lt;span class=&quot;page-numbers dots&quot;&gt;&amp;hellip;&lt;/span&gt; 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-&gt;__construct('&lt;span class=&quot;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 />

标签: phpwordpress

解决方案


推荐阅读