Pergunta

I have a custom post type (question) related to a custom taxonomy (support)

In my-theme/taxonomy.php I have this code:

<?php

$taxonomy = get_queried_object()->taxonomy;

if ($taxonomy == 'support')
{
    get_template_part('template/support/categories');
    exit;
}

wp_safe_redirect(site_url('/'));
exit;

?>

Means I target a specific template file for "support" taxonomy.

In my taxonomy template file I make a custom query:

<?php $current_category = get_term_by('id', get_queried_object()->term_id, 'support'); ?>

<?php $questions = new WP_Query(array(
    'post_type' => array('question'),
    'post_status' => 'publish',
    'posts_per_page' => 5,
    'posts_per_archive_page' => 5,
    'paged' => ((get_query_var('page')) ? get_query_var('page') : 1),
    'nopaging' => false,
    'tax_query' => array(
        array(
            'taxonomy' => 'support',
            'terms' => array($current_category->term_id)
        )
    ),
    'orderby' => 'menu_order',
    'order' => 'ASC'
)); ?>

<?php if ($questions->have_posts()): ?>
    <ul class="list normalize">
        <?php while ($questions->have_posts()) : $questions->the_post(); ?>
            <li>
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <?php the_excerpt(); ?>
            </li>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>

<div class="nav-previous">
    <?php next_posts_link( __('Previous', 'my-theme'); ?>
</div>

<div class="nav-next">
    <?php previous_posts_link( __('Next', 'my-theme'); ?>
</div>

<?php wp_reset_postdata(); ?>

I have about 11 posts, page 1 shows the 5 first posts, but the problem is that no pagination is shown.

Any idea? Thank you

Foi útil?

Solução 2

I tried Your code and with my taxonomy

<?php $questions = new WP_Query(array(
    'post_type' => array('studies'),
    'post_status' => 'publish',
    'posts_per_page' => 15,    
    'paged' => get_query_var('paged'),
    'nopaging' => false,
    'tax_query' => array(
        array(
            'taxonomy' => 'studies',
            'terms' => 11
        )
    ),
    'orderby' => 'menu_order',
    'order' => 'ASC'
));


?>

<div class="grid9">
<div class="entry-content">
<?php if ($questions->have_posts()): ?>
    <ul class="list normalize">
        <?php while ($questions->have_posts()) : $questions->the_post(); ?>
            <li>
                <h3><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></h3>                
            </li>
        <?php endwhile; ?>
    </ul>

<?php endif; ?>
<?php
wp_pagenavi( array( 'query' => $questions ) ); 
?>

This works fine ,Don't forget to use wp-pagenavi plugin.

Outras dicas

You can try this pagination plugin

http://wordpress.org/plugins/wp-pagenavi/

And add this code in your template

<?php if (!function_exists('wp-pagenavi')) { wp_pagenavi(); } else { ?>
    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div><?php } ?>

Put this code above the "endif;" and just below the end of while loop.

 <div class="nav-previous">
    <?php next_posts_link( __('Previous', 'my-theme'); ?>
</div>

<div class="nav-next">
    <?php previous_posts_link( __('Next', 'my-theme'); ?>
</div>

<?php wp_reset_postdata(); ?>

Hope this helps you.

Ussually this works for me: $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $questions->max_num_pages ) );

Notice the question variable. :-) After you use this, go to Settings->Permalink and Save twice.

You can find a bigger tutorial here with the same example.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top