我列出了一个名为ad
使用get_posts
wich工作正常,
我的问题是我不能阅读paged
param,我需要它才能启用分页,
问题是:
get_query_var(\'paged\')
或$paged
都是0
url如下所示:
http://webiste.com/ads/?paged=2
我甚至想把
query_vars
function query_vars($public_query_vars) {
$public_query_vars[] = "paged";
}
add_filter(\'query_vars\', \'query_vars\');
你知道我错过了什么吗?
-编辑-
这就是我正在做的:
在里面functions.php
function get_anunciantes($params,$debug = false) {
if ($debug ) {
echo \'<pre style="background:#333"> \';
print_r( $params );
echo \'</pre>\';
}
$area_slug = $params[\'area_slug\'];
$category_slug = $params[\'category_slug\'];
if ( !empty ( $category_slug ) ) {
$category_params = array(
\'taxonomy\' => \'category\',
\'field\' => \'slug\',
\'terms\' => array("$category_slug")
);
} else {
$category_params = array();
}
if ( !empty ( $area_slug ) ) {
$area_params = array(
\'taxonomy\' => \'area\',
\'field\' => \'slug\',
\'terms\' => array("$area_slug")
);
} else {
$area_params = array();
}
if ( !empty( $area_params ) && !empty( $category_params ) ){
$tax_params = array(
\'relation\' => \'AND\',
$area_params,
$category_params
);
} else if ( !empty( $area_params ) ){
$tax_params = array($area_params);
} else {
$tax_params = array();
}
$today = time(); /* 1407375843 */
$current_page = $params[\'current_page\'];
/*$ipp = 5;
$offset = $current_page * $ipp;*/
$myposts = get_posts( array (
\'posts_per_page\' => 5,
\'paged\' => $current_page,
/*\'showposts\' => -1,*/
\'post_type\' => \'ad\',
\'post_status\' => \'publish\',
\'tax_query\' => $tax_params,
\'meta_query\' => array(
array(
\'key\' => \'wpcf-start-date\',
\'value\' => $today,
\'compare\' => \'<=\',
\'type\' => \'NUMERIC\'
),
array(
\'key\' => \'wpcf-end-date\',
\'value\' => $today,
\'compare\' => \'>\',
\'type\' => \'NUMERIC\'
)
)
)
);
$data = array(
\'myposts\' => $myposts,
\'pages\' => 6 /* static, i haven\'t done it yet */
);
return $data;
}
在模板中
ads.php
使用页面的:
<div class="entry-content">
<?php the_content(); ?>
<?php echo $area_slug.\' > \'.$category_slug; ?>
<ul>
<?php
$params = array(
\'area_slug\' => $area_slug,
\'category_slug\' => $category_slug,
\'current_page\' => get_query_var(\'current_page\')
);
$result = get_anunciantes($params,false);
$myposts = $result[\'myposts\'];
foreach ($myposts as $mypost) { ?>
<li>
<h3><a href="<?php echo get_permalink($mypost->ID ); ?>"><?php _e( $mypost->post_title ); ?></a></h3>
<?php echo get_the_post_thumbnail($mypost->ID, \'thumbnail\'); ?>
<p class="phone"><?php echo $meta[\'wpcf-phone\'][0]; ?></p>
</li>
<?php } ?>
</ul>
Paged <?php echo get_query_var(\'paged\'); echo \'-\'.$paged /* ALLWASY 0 */ ?>
<?php
for ($i = 1; $i <= $result[\'pages\']; $i++) {
echo \'<a href="?paged=\'.$i.\'" class="\'.( $current_page == $i ? \'current\' : \'\' ).\'">\'.$i.\'</a>\';
} ?>
</div>