WordPress.org

Ready to get started?Download WordPress

Forums

Next page navigation doesn't work (8 posts)

  1. bcorrigan
    Member
    Posted 5 years ago #

    Thanks for all help in advance.
    I am using Atahualpa Theme 2.2.1 with pageNavi and permalinks. I get 404 errors for pages after the first page.
    Website: https://depts.washington.edu/ophthweb/wordpress
    everything works ok on the home page when showing most recent posts, e.g., http://depts.washington.edu/ophthweb/wordpress/ and http://depts.washington.edu/ophthweb/wordpress/page/2/

    but if I use a link to a permalink, e.g.,
    http://depts.washington.edu/ophthweb/wordpress/faculty/

    I get a 404 error on page 2 and beyond (../page/2/)

    my .htaccess file is writable.
    Here's a snippet of a category page (category-38.php. 38 is the category ID for faculty).
    All I added was an H2 header and query_posts line and commented out the_time and the_author in the loop.

    any ideas on what I'm missing?

    -Bill
    ------

    <h2>Opthalmology Faculty</h2>
    
    	<?php //query_posts(array('category__and' => array(50,38)));
    	?>
    
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<h2><a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<small><!-- <?php the_time('F jS, Y') ?>  by <?php the_author() ?> --></small>
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				<p class="postmetadata"><?php the_tags('Tags: ', ', ', ''); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div>
    
    		<?php endwhile; ?>
    <p>category-38.php</p>
    	<?php if(function_exists('wp_pagenavi')) { ?>
    		<div class="wp-pagenavi-navigation">
    			<?php wp_pagenavi(); ?>
    		</div>
    	<?php } else { ?>
    		<div class="navigation">
    			<div class="older"><?php next_posts_link(__('&laquo; Older Entries', 'atahualpa')); ?></div>
    			<div class="newer"><?php previous_posts_link(__('Newer Entries &raquo;', 'atahualpa')); ?></div>
    			<div style="clear:both"></div>
    		</div>
    	<?php } ?>
    
    	<?php else : ?>
    		<h2 class="center"><?php _e('Not Found', 'atahualpa'); ?></h2>
    		<p class="center"><?php _e('Sorry, but you are looking for something that is not here.', 'atahualpa'); ?></p>
    		<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    	<?php endif; ?>

    ------

  2. bytesforall
    Member
    Posted 5 years ago #

  3. xiaolai
    Member
    Posted 5 years ago #

    I've fixed this, here's the notes I've post on myblog(http://www.lixiaolai.com):
    This is not because of your .htaccess configuration, but becausae of the mechanism of the query_post() function used by WordPress. When you're using "index.php" as your "homepage", the default query is used, but if you're using "home.php" as your homepage (or you're using a page template elsewhere), you're in fact expected to use a customized query.

    In any page template, including user-defined "home.php", you'd better define your own query, don't simply write:

    
    <?php query_posts(); ?>
    <?php query_posts( 'posts_per_page=25' ); ?>
    

    rahter, you should construct a new instance of $wp_query:

    <?php
    $myqueryname = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=5'.'&paged='.$paged);
    ?>

    ..., and then you can start the loop:

    <?php if (have_posts()) : ?>
      <?php while (have_posts()) : the_post(); ?>
      ... do whatever you like
      <?php endwhile; ?>
    <?php else : ?>
      ... what if there's no post matching myquery?
    <?php endif; ?>

    ... and now your navigation links should work properly:

    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More »') ?></div>
    </div>

    ... and, you'd better not to forget destruct your instance of $wp_query:

    <?php $wp_query = null; $wp_query = $myqueryname;?>

    Here's the complete code of a page template that has working navigation links:

    <?php
    /*
    Template Name: //Define Your Template Name Here
    */
    ?>
    
    <?php get_header(); ?>
      <?php
      $myqueryname = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query();
      $wp_query->query('showposts=25'.'&paged='.$paged);
    ?>
      <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
        ...
        <?php endwhile; ?>
      <?php else : ?>
      ...
      <?php endif; ?>
    
    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More »') ?></div>
    </div>
    
    <?php $wp_query = null; $wp_query = $myqueryname;?>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  4. tjobbe
    Member
    Posted 5 years ago #

    Hi xiaolai, I used your method above and I do now have a More> link on my page, but when i click the link it still shows the same data.

    http://www.ribs4u.co.uk/ribs-in-stock/page/2/ is the same as http://www.ribs4u.co.uk/ribs-in-stock/

    This is my php:

    <?php get_header(); ?>
    <div id="content">
      <?php
      $myqueryname = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query();
      $wp_query->query('showposts=5'.'&paged='.$paged);
    ?>
      <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<!--h2><a href="<?php //the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php //the_title_attribute(); ?>"><?php //the_title(); ?></a></h2>
    			<small><?php //the_time('F jS, Y') ?> <!-- by <?php //the_author() ?> --></small-->
    			<div class="entry clearfix">
    				<?php the_content('</p><p class="moreLink">Click here for the full boat details &raquo;'); ?>
    			</div>
    			<!--p class="postmetadata"><?php //the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php //the_category(', ') ?> | <?php //edit_post_link('Edit', '', ' | '); ?>  <?php //comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p-->
    		</div>
        <?php endwhile; ?>
      <?php else : ?>
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
      <?php endif; ?>
    
    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More »') ?></div>
    </div>
    
    <?php $wp_query = null; $wp_query = $myqueryname;?>
    	</div>
    	<?php get_sidebar(); ?>
    </div>
    <?php get_footer(); ?>
  5. tecnosh
    Member
    Posted 5 years ago #

    this works in every page template.. but not on index. someone knows why?

  6. levani01
    Member
    Posted 4 years ago #

    How can I use this code to query posts only by certain IDs?

  7. levani01
    Member
    Posted 4 years ago #

    ?????

  8. blueskies
    Member
    Posted 4 years ago #

    levani01 - in case you haven't resolved this: you'll want to add parameters to your query_posts
    http://codex.wordpress.org/Template_Tags/query_posts

    such as query_posts('p=5');

    and thanks, xiaolai, I think this is what I've been looking for.

Topic Closed

This topic has been closed to new replies.

About this Topic