0

I have a situation and all the searching I've done hasn't led me to a successful outcome. I have a static homepage template with a custom wp_query that looks like the following (which works on another site on a custom page--Also, I have posts_per_page set to 1 for testing purposes and I have posts set to 1 in the dashboard):

<?php 
    global $paged;
    global $bday_parties;
    $temp = $bday_parties; 
    $bday_parties = null; 

    $bday_parties = new WP_Query(); 
    $bday_parties->query('category_name=party-themes&posts_per_page=1&post_type=page'.'&paged='.$paged);
    while ($bday_parties->have_posts()) : $bday_parties->the_post(); 
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <div class="article-border">
        <?php get_template_part('partials/loop-homeparties'); ?>
    </div>      
</article>

<?php endwhile; ?>
<div class="pagination">
    <?php wp_pagenavi( array( 'query' => $bday_parties ) ); ?>
</div>
<?php 
    $bday_parties = null; 
    $bday_parties = $temp; 
?>

The partials/loop-homeparties template is pulling meta values from custom meta boxes on a page and that content is making up the "posts" on the homepage (as well as on archive pages).

Using the above query, I get the content on the home page, I get the nav links but when I click (the link shows the URL for the next page) the home page just reloads. I've been working on this for a couple of days now and the site needs to launch soon (this is holding me up). Since it works on another page successfully, I don't understand why it isn't working for me here. Any help would be appreciated.

TIA!

1

1 Answer 1

1

Since it works on another page successfully, I don't understand why it isn't working for me here.

The problem is other page is not Static Front Page. When paging a static page, WordPress use the page variable, not the paged query variable. Pages use <!--nextpage--> to paginate. From the WP_Query page:

Pagination Note: Use get_query_var('page'); if you want your query to work in a Page template that you've set as your static front page. The query variable 'page' also holds the pagenumber for a single paginated Post or Page that includes the <!--nextpage--> Quicktag in the post content.

Display posts from current page on a static front page:

$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query = new WP_Query( array( 'paged' => $paged ) );

In your code, this:

global $paged;
global $bday_parties;
$temp = $bday_parties;
$bday_parties = null;

$bday_parties = new WP_Query();
$bday_parties->query('category_name=party-themes&posts_per_page=1&post_type=page'.'&paged='.$paged);
while ($bday_parties->have_posts()) : $bday_parties->the_post();

Could be rewritten as this:

global $bday_parties;

$temp = $bday_parties;
$bday_parties = null;

$bday_parties = new WP_Query();

$page_number = ( get_query_var('page') ) ? get_query_var('page') : 1;

$bday_parties->query( 'category_name=party-themes&posts_per_page=1&post_type=page&page=' . $page_number );
10
  • Thanks Charles, I just tried your code and it didn't work. I've basically tried every bit of code I've come across and I can't get anything to work. I'd be happy to settle for "Next/Prev" links at this point. Aug 14, 2013 at 15:40
  • @JusticeIsCheap "didn't work" is no proper error or problem description.
    – kaiser
    Aug 14, 2013 at 15:40
  • When I say "didn't work" I'm getting the exact same results as my code I posted. It's still reloading the same page. Aug 14, 2013 at 15:57
  • What url did you use to find for page 2? If you are using the link from the wp_pagenavi function. What url is it producing? Aug 14, 2013 at 16:02
  • 1
    You should ask a new question for that. The comments is not a good place to answer new questions. I'm glad you stopped using a static front page. The WP programmers never intended for that option to be paged. None of the next / previous link functions do not work on static front pages. Aug 14, 2013 at 17:28

Your Answer

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

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