0

Good afternoon all,

I have a custom taxonomy called 'Gallery' and a have created a new page template to pull in and paginate all posts in the 'gallery' taxonomy.

This works fine (as a page), however I would like to set this page as the WordPress static 'Front page'.

When I set this page template as the 'Front page' the pagination no longer works. I have tried many solutions today and would really appreciate some help on this one!

Any help/tips massively appreciated!

Thanks.

My Code:

<?php

if ( get_query_var('paged') ) {
    $paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
    $paged = get_query_var('page');
} else {
    $paged = 1;
}

$args = array(
'post_type' => 'gallery',
'paged' => $paged,
'orderby' => 'menu_order',
'order' => 'DESC'
);
query_posts( $args );

if ( have_posts()) : while( have_posts() ) : the_post(); ?>

    <!-- List Posts -->

<?php endwhile; ?>

<nav>
    <?php previous_posts_link( __( 'Previous', 'framework' ) ); ?>
    <?php next_posts_link( __( 'Next', 'framework' ) ); ?>
</nav>

<?php else : ?>

    <!-- No Posts -->

<?php endif; ?>

<?php wp_reset_postdata(); ?>

EDIT:

If I add global $paged; before the if statements it does works perfectly. Could anyone educate me on what I was missing?

Also what are the performance implications (if any) of calling global $paged; on the homepage?

  • Can you elaborate on what's not working? Are your previous and next links not showing? Do they show but don't change the content? – Jared Feb 28 '13 at 14:41
  • Its odd, the 'next' link shows, but not the 'prev' link. So if I were to show two posts per page and there were 6 posts, Page 1 links to Page 2 and that it, no more pages, no previous links. EDIT: if I add global $paged; before the initial if statement it works perfectly. –  Feb 28 '13 at 14:45

2 Answers2

2

Add global $paged; before any code runs.

0

global $paged works throughout the WordPress, to access this we need to put it before usage like your case is. Yes, there is no issue at all to use this variable and you are in totally safe hands. Actually, $paged variable is getting posts for each page and once you are using this variable its showing up data appropriately. There are other global variables as well to be used in WordPress, for whole list you can visit this official codex page https://codex.wordpress.org/Global_Variables

I hope after reading this comment and going through this URL your all points will be solved and you can utilize all this info in future as well with best approach ...

laraib
  • 611
  • 5
  • 16