Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've installed the wp_pagination plugin and it appears to be working fine at the bottom of the page, however, the pagination is not displaying at the top of the page. Below is the template code:

<?php
/*
Template Name: Press
*/
get_header(); ?>
    <div id="primary">
        <div id="content" role="main">
            <header class="page-header">
                <h1 class="entry-title"><?php wp_title(); ?></h1>
            </header>
            <?php if(function_exists('wp_paginate')) {
                wp_paginate('range=4&anchor=2&nextpage=Next&previouspage=Previous');
            } ?>
            <?php
             query_posts( array( 'posts_per_page' => 6, 'cat' => 16, 'paged' => get_query_var('paged') ) ); 
            while (have_posts()) : the_post();
             ?>
            <div class="news-dir">
                <h3><a href="<?php echo get_permalink(); ?>"><?php the_title();?></a></h3>
                    <?php 
                    global $more;    // Declare global $more (before the loop).
                    $more = 0;       // Set (inside the loop) to display content above the more tag.
                    the_content("More...");
                    ?>
            </div>
            <?
            endwhile;
            ?>

            <?php if(function_exists('wp_paginate')) {
                wp_paginate('range=4&anchor=2&nextpage=Next&previouspage=Previous');
            } ?>
        </div><!-- #content -->
    </div><!-- #primary -->

Why isn't it working at the top?

MTIA!

share|improve this question

3 Answers 3

up vote 0 down vote accepted

query_posts() overwrites the original query, and the pagination gets the original before the query_posts() call and the changed after it.

Solution: Don’t use query_posts(), filter pre_get_posts instead. We have tons of examples for that on our site. :)

Here is some pseudo code (meaning: not tested).

add_filter( 'pre_get_posts', 'wpse_58843_list_cat_16' );

function wpse_58843_list_cat_16( $query )
{
    // make sure this matches your template’s file name.
    // See http://codex.wordpress.org/Function_Reference/is_page_template
    if ( ! is_page_template( 'press.php' ) )
    {
        return $query;
    }

    $query->set( 'cat',            16 );
    $query->set( 'posts_per_page', 6 );
    $query->set( 'post_type',      'post' );

    return $query;
}
share|improve this answer
    
thanks, I can see the problem now, but I don't understand how to use pre_get_posts to get the posts. I need to write a function for that? –  circey Jul 19 '12 at 1:22
    
@circey I have added some sample code and a link to related questions with more examples. –  toscho Jul 19 '12 at 5:58

Put this:

<?php if(function_exists('wp_paginate')) {
                wp_paginate('range=4&anchor=2&nextpage=Next&previouspage=Previous');
            } ?>

just before this line:

<div class="news-dir">
share|improve this answer
    
That just means that there is pagination within the while statement, and creates a pagination area within each and every "news-dir" div. –  circey Jul 18 '12 at 8:35
    
Shoot! didn't think it through. The way you are trying should work fine... read toscho's answer above. could work... –  Towfiq Jul 18 '12 at 12:02

Have you checked your HTML source ?

Maybe you should check the css and determine that there is no problem with the visibility of generated HTML if it appears on page source.

share|improve this answer
    
Yes, I should've mentioned it in my post, sorry. Source shows the navigation div as <div class="navigation"></div>, ie. it's empty. Can't see how it could be a CSS issue because the pagination displays without any problems at the bottom of the page. –  circey Jul 18 '12 at 8:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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