简体   繁体   中英

Wordpress next_posts_link() only reloads the same page

I'm having a problem with my Wordpress theme. My next_posts_link() only reloads the same page. Here's my code.

    <div id="main">

    <?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="utdrag">
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    <div class="crop"><a href="<?php the_permalink(); ?>">
    <?php 
    if ( get_the_post_thumbnail($post_id) != '' ) {

    echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
    the_post_thumbnail();
    echo '</a>';

    } else {


    echo '<img src="';
     echo catch_that_image();
    echo '" alt="Image unavailable" class="crop" />';
     echo '</a>';

    }

    ?></a>
    </div>
    <?php the_excerpt(); ?>
</div>
    <?php endwhile; else: endif; ?>

    <?php next_posts_link();?><?php previous_posts_link();?>


</div>

I'm using a static page as my front page. As you can see it's only displaying posts that have the same category as the page title: query_posts('category_name='.get_the_title().'&post_status=publish,future');

This is something I want to keep. So does anyone know why it just reloads? Why it isn't changing to the next page?

These two functions does not work on static pages.

From the documentation for wp_next_post_link() :

This function does not work with static pages.

However, take a look at this article. It talks about how to create a static front page with dynamic content.

I figured it out! I'm posting it here in case someone else is having the same problem!

I added this code at the top:

<?php if ( get_query_var('paged') ) {
     $paged = get_query_var('paged'); 
     }
    elseif ( get_query_var('page') ) { 
    $paged = get_query_var('page'); 
    }
    else { $paged = 1; }
?>

And replaced this:

<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>

with this:

<?php query_posts('catery_name='.get_the_title().'&showposts=2'.'&paged='.$paged); ?>

For more information, check out this link: http://wordpress.org/support/topic/front-page-wp-query-pagination-issue-repeating-posts-next_posts_link-help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM