Take the 2-minute tour ×

I would like to build on this answer so I can incorporate pagination and a couple of other features.

We have over 1,600 entries in our Glossary so certain letters have far more than 20 (my max posts/page) entries.

If a user clicks "A" or accesses "/dev/glossary/a" I'd like them to see a list of all entries with parent "A".

I'd also like:

  • The list to be in alphabetical order
  • The number of entries for this parent to be displayed at the top of the page
  • The list to be paginated

I've had a basic attempt at this using $paged = (get_query_var('page')) ? get_query_var('page') : 1; and the paged argument in the WP_Query, but my next_posts_link doesn't even display.

I'm not quite sure where to begin with this so any guidance would be much appreciated.

share|improve this question
Just to clarify, if you're listing all entries, where would the pagination come in? –  CookiesForDevo Mar 17 '12 at 14:51
Sorry, what I mean is, I'd like the user to be able to see 20 entries at a time, but I'd like all of the entries to be accessible via the pagination (i.e. click "next page" a few times and the third lot of 20 glossary entries under "A" would be displayed). –  dunc Mar 17 '12 at 17:34

3 Answers 3

up vote 1 down vote accepted

Something like this should do the trick for ordering by title, and using pagination:

    global $wp_rewrite, $wp_query;

    <header class="entry-header">

    <?php   //If top level, find children
        if($post->post_parent == 0):
            $children = new WP_Query(array(
                'paged' => $paged,
                'posts_per_page' => 20,
                'orderby' => 'title',
                'order' => ASC

            if($children->have_posts()): ?>
                <?php while ( $children->have_posts() ) : $children->the_post(); ?>
                <?php endwhile; ?>


                $pagination = array(
                    'total' => $wp_query->max_num_pages,
                    'current' => $current

                if( $wp_rewrite->using_permalinks() )


                <?php echo paginate_links( $pagination ); ?>

            <?php else: ?>
                <?php echo 'No children';?>
            <?php endif; ?>

            <?php wp_reset_postdata(); ?>
        <?php else://Not top level, display normal post ?>
            <?php the_content(); ?>
        <?php endif;?>

<?php endif; ?>

You can move the paginate_links function to wherever you want the pagination to go.

As for displaying the total number of entries, you can use the $wp_query variable inside of the loop.

<?php echo $wp_query->found_posts; ?>

share|improve this answer

i wrote about creating a custom 'glossary' taxonomy from post titles. it isn't perfect, but it might be relevant:


it is automatic, but there is not reason you couldn't add a metabox, if the auto-generated letters aren't working quite well enough.

from there i'd probably use the pre_get_posts() hook to force 20 posts/page and alphabetical orderby (kind of can't believe i didn't already have the orderby... should probably update my tutorial at some point.

share|improve this answer

Thanks to @DaveHunt's answer as well as this excellent answer, I've been able to put the following code together.

It's important to note that because the page is_single(), the paged variable will always be set to 1. I spent a lot of time on this because of that oversight on my part!

if($post->post_parent == 0):

    if ( get_query_var( 'tpage' ) > 0 )
        $paged = get_query_var( 'tpage' );
        $paged = 1;

    $base = trailingslashit( get_permalink( $post->ID ) );

    $children = new WP_Query( array(
        'paged' => $paged,
        'posts_per_page' => 20,
        'orderby' => 'title',
        'order' => ASC
    ) );


            <?php get_template_part( 'list', 'glossary' ); ?>
        <?php endwhile; ?>


            $links = array(
                'base' => $base . 'tpage/%#%',
                'total' => $children->max_num_pages,
                'current' => $paged


        <div class="navigation">
            <?php echo paginate_links( $links ); ?>

    <?php else: ?>
        Sorry, there are no entries in our glossary for this letter.
    <?php endif; ?>

    <?php wp_reset_postdata(); ?>

<?php else : ?>

Hope this helps any other users coming across a similar problem.

share|improve this answer

Your Answer


