下面的代码(我在函数中使用)来自https://stackoverflow.com/questions/35263445/numeric-pagination-on-my-custom-category-page, 并显示“Undefined variable:additional\\u loop”和“Trying to get property of non object”的调试消息。
function paginate ( $pages = \'\', $range = 3 ) {
$showitems = ( $range * 2 ) +1;
global $paged;
if ( empty ( $paged ) ) $paged = 1;
if ( $pages == \'\' ) {
global $wp_query;
$pages = $wp_query->max_num_pages;
if ( !$pages ) {
$pages = 1;
} }
if ( 1 != $pages ) {
echo "<p class=\\"paginate\\"><span>Page ".$paged." of ".$pages." </span>";
if ( $paged > 2 && $paged > $range+1 && $showitems < $pages ) echo " <a href=\'".get_pagenum_link ( 1 ) ."\'>« First</a> ";
if ( $paged > 1 && $showitems < $pages ) echo " <a href=\'".get_pagenum_link ( $paged - 1 ) ."\'>‹ Previous</a> ";
for ( $i=1; $i <= $pages; $i++ ) {
if ( 1 != $pages && ( ! ( $i >= $paged+$range+1 || $i <= $paged-$range-1 ) || $pages <= $showitems ) ) {
echo ( $paged == $i ) ? "<span class=\\"current\\"> ".$i." </span>":"<a href=\'".get_pagenum_link ( $i ) ."\' class=\\"inactive\\"> ".$i." </a>";
} }
if ( $paged < $pages && $showitems < $pages ) echo " <a href=\\"".get_pagenum_link ( $paged + 1 ) ."\\">Next ›</a> ";
if ( $paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages ) echo " <a href=\'".get_pagenum_link ( $pages ) ."\'>Last »</a> ";
echo "</p>\\n";
} }
还有。。。
if (function_exists( \'paginate\' ) ) {
paginate( $additional_loop->max_num_pages );
}
我需要更改什么来修复它?
@kero在评论中要求包含更多我正在使用的代码,下面是查询(位于页面模板中(以及“if function\\u exists”内容)。
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query( array(
\'post_type\' => \'item\',
\'posts_per_page\' => \'5\',
\'orderby\' => \'date\',
\'order\' => \'desc\',
\'paged\' => $paged,
) );