• Resolved egr102

    (@egr102)


    I’m trying to setup a loop in WordPress that will show all posts from one category, which is working just fine, however my problem is that my ‘next_posts_link’ and ‘previous_posts_link’ doesn’t work. They navigate between pages just fine but the results are the same as the first page all the time.

    <?php get_header(); ?>
    
    <div id="main" role="main">
    
    <?php
    if (is_home()) {
    query_posts("cat=-6");} //Exclude work posts (cat 6) from the news page
    ?>
    
    <div class="inner">
    
    <h1><?php trim(wp_title("")); ?></h1>
    
    <?php include ('sidebartwo.php'); ?>
    
    <section class="main-wrap twocol news">
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <article class="box-style">
    
    <time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
    
    <h2><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?>
    </a></h2>
    
    <?php the_content(''); ?>
    
    </article>
    
    <?php endwhile; ?>                              
    
    <div class="next-prev-wrap">
    
    <!-- This is what isn't working properly -->
    <span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
    <span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?>
    <!-- /end -->
    
    </span>
    
    </div>
    
    </section>      
    
    <?php endif; ?>
    
    </div> <!-- /inner -->
    
    </div> <!-- /main -->
    
    <?php get_footer(); ?>

    I don’t think I’m using the right syntax, in fact according to the WP codex page, I don’t even think my next/prev links are able to work the way I want it to. How should I approach this?

    I’d really appreciate any help people could give.

Viewing 1 replies (of 1 total)
  • Thread Starter egr102

    (@egr102)

    Fixed myself. This post is now resolved. After much (and I mean much) Googling, I found this article which solved my problem: https://www.dynamicwp.net/articles-and-tutorials/pagination-problem-when-excluding-certain-category-from-blog-main-page/

    For reference my new code looks like this:

    <?php get_header(); ?>
    
    <div id="main" role="main">
    
    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-6&paged=$paged");
    }
    ?>
    
    <div class="inner">
    
    <h1><?php trim(wp_title("")); ?></h1>
    
    <?php include ('sidebartwo.php'); ?>
    
    <section class="main-wrap twocol news">
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <article class="box-style">
    
    <time><?php the_time('M d') ?><span><?php the_time('Y') ?></span></time>
    
    <h2><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    
    <?php the_content(''); ?>
    
    </article>
    
    <?php endwhile; ?> 		    				 	
    
    <div class="next-prev-wrap">
    
    <span class="next"><?php next_posts_link( 'Older posts', $post->max_num_pages ); ?></span>
    <span class="prev"><?php previous_posts_link( 'Newer posts', $post->max_num_pages ); ?></span>
    
    </div>
    
    </section>    	
    
    <?php endif; ?>
    
    </div> <!-- /inner -->
    
    </div> <!-- /main -->
    
    <?php get_footer(); ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Why isn't my WordPress next_posts_link not working with exclude category loop?’ is closed to new replies.