I've just finished building a custom page template using the following code. The issue is the pagenav doesn't work - But works on every other page with multiple posts. I want this one to appear if there is more then 5 posts in that relevant Category.
<?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(); ?>
Code for the wpld_pagenavi function to produce the 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>';
}
If someone could kindly explain to me why its not appearing that would be fantastic!
Many Thanks