0

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'] = '&laquo; Previous'; //text of the "Previous page" link
    $a['next_text'] = 'Next &raquo;'; //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

1 Answer 1

0

Your navigation function seems to take data from main query (global $wp_query) variable.

However what you have on custom page is a completely separate query (new WP_Query()), which doesn't modify main one (as it shouldn't).

The best way would probably be to modify your pagination function to optionally accept custom query object as argument to be used instead of main one.

1
  • Rarst - could you kindly point out what I'd need to change in the pagination function. Sorry I'm new to this type of function and how it works.
    – dannyw24
    Commented Nov 7, 2013 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.