Pagination with custom post types and WP_Query();
-
Hi there,
I am trying to get my custom post types paged but with the result that there is no navigation on the bottom of the list:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; // display posts $args = array( 'post_type' => 'review-module', 'post_status' => 'publish', 'posts_per_page' => $quotes_quantity, 'paged' => $paged, 'reviews' => $quotes_taxonomy, 'orderby' => $quotes_order, // rand or date 'order' => 'ASC' ); $queryObject = new WP_Query($args); if ($queryObject->have_posts()) : while ($queryObject->have_posts()) : $queryObject->the_post();This could be due to my usage of this script for the pagination, which actually worked in earlier versions of WP.
// advanced Pagination ################################ function emm_paginate($args = null) { $defaults = array( 'page' => null, 'pages' => null, 'range' => 3, 'gap' => 3, 'anchor' => 1, 'before' => '<hr /><div class="emm-paginate">', 'after' => '</div>', 'title' => __('Pages:'), 'nextpage' => __('»'), 'previouspage' => __('«'), 'echo' => 1 ); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if (!$page && !$pages) { global $wp_query; $page = get_query_var('paged'); $page = !empty($page) ? intval($page) : 1; $posts_per_page = intval(get_query_var('posts_per_page')); $pages = intval(ceil($wp_query->found_posts / $posts_per_page)); } $output = ""; if ($pages > 1) { $output .= "$before<span class='emm-title'>$title</span>"; $ellipsis = "<span class='emm-gap'>...</span>"; if ($page > 1 && !empty($previouspage)) { $output .= "<a href='" . get_pagenum_link($page - 1) . "' class='emm-prev'>$previouspage</a>"; } $min_links = $range * 2 + 1; $block_min = min($page - $range, $pages - $min_links); $block_high = max($page + $range, $min_links); $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false; $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false; if ($left_gap && !$right_gap) { $output .= sprintf('%s%s%s', emm_paginate_loop(1, $anchor), $ellipsis, emm_paginate_loop($block_min, $pages, $page) ); } else if ($left_gap && $right_gap) { $output .= sprintf('%s%s%s%s%s', emm_paginate_loop(1, $anchor), $ellipsis, emm_paginate_loop($block_min, $block_high, $page), $ellipsis, emm_paginate_loop(($pages - $anchor + 1), $pages) ); } else if ($right_gap && !$left_gap) { $output .= sprintf('%s%s%s', emm_paginate_loop(1, $block_high, $page), $ellipsis, emm_paginate_loop(($pages - $anchor + 1), $pages) ); } else { $output .= emm_paginate_loop(1, $pages, $page); } if ($page < $pages && !empty($nextpage)) { $output .= "<a href='" . get_pagenum_link($page + 1) . "' class='emm-next'>$nextpage</a>"; } $output .= $after; } if ($echo) { echo $output; } return $output; } function emm_paginate_loop($start, $max, $page = 0) { $output = ""; for ($i = $start; $i <= $max; $i++) { $output .= ($page === intval($i)) ? "<span class='emm-page emm-current'>$i</span>" : "<a href='" . get_pagenum_link($i) . "' class='emm-page'>$i</a>"; } return $output; }So the output of my navigation code on the bottom of my custom post type list looks like this:
// get pagination function from the functions.php
if (function_exists(“emm_paginate”)) emm_paginate();Any idea what I am doing wrong?
Any help is much appreciated.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Pagination with custom post types and WP_Query();’ is closed to new replies.