添加此分页功能:
function pagination( $query, $baseURL = get_bloginfo( $url ), $echo = true ) {
$page = $query->query_vars["paged"];
if ( !$page ) $page = 1;
$qs = $_SERVER["QUERY_STRING"] ? "?".$_SERVER["QUERY_STRING"] : "";
// Only necessary if there\'s more posts than posts-per-page
if ( $query->found_posts > $query->query_vars["posts_per_page"] ) {
$re = \'<ul class="paging">\';
// Previous link?
if ( $page > 1 ) {
$re .= \'<li class="previous"><a href="\'.$baseURL.\'page/\'.($page-1).\'/\'.$qs.\'">« previous</a></li>\';
}
// Loop through pages
for ( $i=1; $i <= $query->max_num_pages; $i++ ) {
// Current page or linked page?
if ( $i == $page ) {
$re .= \'<li class="active">\'.$i.\'</li>\';
} else {
$re .= \'<li><a href="\'.$baseURL.\'page/\'.$i.\'/\'.$qs.\'">\'.$i.\'</a></li>\';
}
}
// Next link?
if ( $page < $query->max_num_pages ) {
$re .= \'<li><a href="\'.$baseURL.\'page/\'.($page+1).\'/\'.$qs.\'">next »</a></li>\';
}
$re .= \'</ul>\';
if ($echo){
echo $re;
}else{
return $re;
}
}
}
然后将分页参数添加到快捷码查询中,并获取当前页面永久链接:
global $post;
$baselink = get_permalink($post->ID);
extract(shortcode_atts(array("country" => \'\' ), $atts));
$country = preg_replace(\'~?*([0-9a-f]+);~ei\', \'chr(hexdec("\\\\1"))\', $country );
$page = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$argsq = array (
\'post_type\' => \'quote\',
\'country\' => $country,
\'orderby\' => \'meta_value\', // you have to specify a meta_key for this to work
\'page\' => $page
);
$testim= get_posts($argsq );
在返回分页和输出之前:
return $output .pagination($testim,$baselink,false);