• Resolved chrismitchell57

    (@chrismitchell57)


    I seem to be having some sort of stupid issue with the next and previous page links for a category page.. It also won't let me exclude a category.

    Any help?

    The code for the page is below:

    <?php get_header(); ?>
    <div class="mini_portfolio_item_category">
                        	<div class="block_inside">
                        		<?php query_posts('posts_per_page=5'); ?>
      <?php while (have_posts()) : the_post(); ?>
    
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <br />
                       <?php the_excerpt(); ?>
    
    	<?php endwhile; ?>
    
    	</div>
    	<div class="navigation">
    		<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    			else { ?>
    
    			<div class="right"><?php next_posts_link('Next Page &raquo;') ?></div>
    			<div class="left"><?php previous_posts_link('&laquo; Previous Page') ?></div>
    			<?php } ?>
    
    	</div>
    
    							</div>
                        </div>
    
                <br />
    
            </div>
        </div>
    
    <?php get_footer(); ?>

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • i can’t see any attempt to exclude a category in your code.

    the parameter are all described in
    https://codex.www.ads-software.com/Template_Tags/query_posts
    https://codex.www.ads-software.com/Template_Tags/query_posts#Category_Parameters
    https://codex.www.ads-software.com/Template_Tags/query_posts#Pagination_Parameters

    for pagination (next/prev posts) you will need to use the ‘paged’ parameter, in connection with a snippet to get the current ‘page’:
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>

    to exclude a category, use the ‘exclude’ parameter.

    the relevant part of your code should be changed from this:

    <div class="block_inside">
                        		<?php query_posts('posts_per_page=5'); ?>
      <?php while (have_posts()) : the_post(); ?>

    to this:

    <div class="block_inside">
    <code><?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?></code>
      <?php query_posts('posts_per_page=5&cat=-23&paged=' . $paged); ?>
      <?php while (have_posts()) : the_post(); ?>

    where 23 is the category ID of the category you want to exclude.

    make a backup copy before editing

    Thread Starter chrismitchell57

    (@chrismitchell57)

    Thanks for the reply alchymyth ??

    The exclude parameter worked ?? but the paged thing didn’t. It still shows the same page over and over again no matter how many times you press previous posts .. very confusing. Should the ‘paged’ query go before the query_posts or after? I tried it before and it came up with a php error on the call_footer.

    the ‘paged’ code should be included as i suggested in the last code snippet – just there:

    (i just see, i got some stray code into it – my bad;
    here the correction – try it this way:)

    <div class="block_inside">
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
      <?php query_posts('posts_per_page=5&cat=-23&paged=' . $paged); ?>
      <?php while (have_posts()) : the_post(); ?>
    Thread Starter chrismitchell57

    (@chrismitchell57)

    all working now ?? thanks alchymyth ??

    Ian

    (@ianaleksander)

    This thread also helped me out – I didn’t really know about the “paged” thing. Seems to be working right now. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Next Page and Previous Page and Category Exclude problem’ is closed to new replies.