我刚刚使用以下代码完成了自定义页面模板的构建。问题是pagenav不起作用,但可以在多个帖子的其他页面上工作。我想这一个出现,如果有超过5个职位在相关类别。
<?php
/*
Template Name: specialoffers
*
*/
?><?php global $up_options ?>
<?php get_header(); ?>
<!-- start midle -->
<div id="midle" class="container">
<div class="block-widget" id="category_slider">
<div class="slider_box">
<ul id="slider">
<li>
<a href="#"><img src="http://www.coastline-leisure.co.uk/v3/wp-content/uploads/2013/11/specialoffers-header.jpg" alt="yorkshire caravan parks"/></a>
</li>
</ul>
</div>
</div>
<div class="clear"></div>
</div>
<!-- end midle -->
<!--start content -->
<div id="main" class="container">
<div class="main_content">
<div class="article left">
<div class="content-special">
<?php
$args = array(
\'post_type\' => \'property\',
\'posts_per_page\' => 5,
\'paged\' => get_query_var( \'paged\' ),
\'tax_query\' => array(
array (
\'taxonomy\' => \'sale_type\',
\'field\' => \'slug\',
\'terms\' => \'special offers\'
)
)
);
$query = new WP_Query ( $args ); ?>
<?php if ($query->have_posts()) : ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<ul class="special_grind_post">
<div class="box-one left">
<?php the_post_thumbnail(\'special\'); ?>
<h3 class="offer-text"><?php the_field(\'special_offer\'); ?></h3>
</div>
<div class="box-two left">
<div class="inside-box">
<h3 class="special-title"><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
<div class="full-details"><a href="<?php the_permalink(); ?>">Full Details</a></div>
</div>
</div>
<div class="box-three left last">
<?php
$attachment_id = get_field(\'location_image\');
$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" />
<h3 class="offer-text"><?php the_field(\'location\'); ?></h3>
</div>
<div class="clear"></div>
</ul>
<?php endwhile; ?>
<?php endif; ?>
<div class="clear">
<?php wpld_pagenavi(); ?>
</div>
<div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<!--end content -->
<?php get_footer(); ?>
wpld\\U pagenavi函数用于生成pagenavi的代码。
function wpld_pagenavi() {
global $wp_query, $wp_rewrite;
$pages = \'\';
$max = $wp_query->max_num_pages;
if (!$current = get_query_var(\'paged\'))
$current = 1;
$a[\'base\'] = ($wp_rewrite->using_permalinks()) ? user_trailingslashit(trailingslashit(remove_query_arg(\'s\', get_pagenum_link(1))) . \'page/%#%/\', \'paged\') : @add_query_arg(\'paged\', \'%#%\');
if (!empty($wp_query->query_vars[\'s\']))
$a[\'add_args\'] = array(\'s\' => get_query_var(\'s\'));
$a[\'total\'] = $max;
$a[\'current\'] = $current;
$total = 1; //1 - display the text "Page N of N", 0 - not display
$a[\'mid_size\'] = 5; //how many links to show on the left and right of the current
$a[\'end_size\'] = 1; //how many links to show in the beginning and end
$a[\'prev_text\'] = \'« Previous\'; //text of the "Previous page" link
$a[\'next_text\'] = \'Next »\'; //text of the "Next page" link
if ($max > 1)
echo \'<div class="navigation">\';
if ($total == 1 && $max > 1)
$pages = \'<span class="pages">Page \' . $current . \' of \' . $max . \'</span>\' . "\\r\\n";
echo $pages . paginate_links($a);
if ($max > 1)
echo \'</div>\';
}
如果有人能友好地向我解释为什么它没有出现,那就太棒了!
非常感谢