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 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!

share|improve this question
    
possible duplicate of How to fix pagination for custom loops? –  Chip Bennett Oct 31 '13 at 14:31
add comment

1 Answer 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 );
share|improve this answer
    
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. –  Justice Is Cheap Aug 14 '13 at 15:40
    
@JusticeIsCheap "didn't work" is no proper error or problem description. –  kaiser Aug 14 '13 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. –  Justice Is Cheap Aug 14 '13 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? –  Charles Clarkson Aug 14 '13 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. –  Charles Clarkson Aug 14 '13 at 17:28
show 5 more comments

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.