Forums

[resolved] posts_nav_link - Page Not Found (11 posts)

  1. Adz
    Member
    Posted 2 years ago #

    Hi

    I've been working on a particular website all day, and it just seems that the moment I fix one thing, another thing breaks. Now it's the turn of the posts_nav_links().

    I originally omitted it from the template (I created it myself) but changed my mind - I don't want to set posts_per_page=-1.
    The first place I put it in was archive.php.

    I'm running one testbed locally and one live on the net - both are as identical as possible (minor configuration differences exist), and have the same issue.

    For testing purposes set posts_per_page=2. I navigate to domainroot/2010/04 and it loads the archive for April 2010 with the two newest posts, as expected. But when I click on the next page link, it comes up with the "page not found" message - which is what it's been set to show in the else section of The Loop. On my local test machine, page/2/ comes up with the error. On the server page/2/ works but page/3/ doesn't.

    I can't make sense of it.
    I'm using WP 2.9.2, and I've got the WP No Category Base plugin enabled. I thought that the plugin may be causing the issue, but it's still broken after I disabled the plugin.

    Any help would be much appreciated.

  2. Adz
    Member
    Posted 2 years ago #

    Sorry to bump my own thread, but anyone have any ideas?

  3. Safirul Alredha (zeo)
    Member
    Posted 2 years ago #

    At least show the code that you're using. Probably you're missing some arguments or need some filter.

  4. Adz
    Member
    Posted 2 years ago #

    archive.php

    <?php get_header(); ?>
    <div id="container">
        <?php get_sidebar(); ?>
    
    	<div id="rightcolumn" class="rightcolumn">
        	<?php  query_posts($query_string . '&posts_per_page=2'); ?>
    		<?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>
            	<div class="post" id="post-<?php echo $post->ID ?>">
                    <?php edit_post_link('[Edit]', '<div class="edit">', '</div>'); ?>
                    <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                    <span class="archiveCatName">
                    <?php
    					foreach((get_the_category()) as $category) {
    						echo(get_category_parents($category->cat_ID ,TRUE, ' '));
    						echo '<br />';
    					} 
    
    				?>
    				</span>
                    <span class="newsDate"><?php the_time('l, F jS Y') ?></span>
    
    			</div><!--End Post-->
    		<?php endwhile;
    		posts_nav_link();
    		else: ?>
    			<h2>Page Not Found</h2>
    			<p>Sorry, the page you were looking for could not be found.</p>
    		<?php endif; ?>
        </div> <!--End Right Column-->
        <br />
        </div> <!--End Container-->
       <?php get_footer(); ?>

    I'm using it without any parameters at the moment until I can get it working properly.

  5. Adz
    Member
    Posted 2 years ago #

    It's decided to use the index.php template rather than archive.php so for some reason, it's not detecting that it's an archive. I don't think the problem is with posts_nav_link() but I don't have a clue what the problem is.

  6. alchymyth
    The Sweeper
    Posted 2 years ago #

    you could try and add the 'paged' parameter.
    the codex is not very helpful there; but see this article:
    http://stylizedweb.com/2008/08/13/query_posts-pagination-problem/

  7. Adz
    Member
    Posted 2 years ago #

    @alchymyth - Thanks for the idea, but I've already tried that. It didn't make a difference. Just for the sake of testing, I also tried navigating to domainroot/2010/?paged=2 but still no luck.

  8. Safirul Alredha (zeo)
    Member
    Posted 2 years ago #

    It can't work like that.

    Create a filter, place it in functions.php instead of querying directly within the archive.php template. Unless the no. of posts per page you set in Options Settings > Reading not exceed the total no. of posts that exist in that category then you can use query_posts() like that. AFAIK.

  9. Adz
    Member
    Posted 2 years ago #

    @Zeo - I have no idea what sort of filter you want me to create and what to do with it. Could you explain it please?

  10. Safirul Alredha (zeo)
    Member
    Posted 2 years ago #

  11. Adz
    Member
    Posted 2 years ago #

    Thank you Zeo. I initially left the posts_per_page in the query string which gave me an odd result - I could get to page 2, but not 3. Once I removed that, it worked perfectly. Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic