Navigation blog page: previous – next
-
Hello,
For my blog I’ve got a new template: blog.php
Here all my blog posts appeares, but with a max limit of 15. The problem:At the bottom of this page, it’s said previous (or next), for navigating to older posts, but when I click, I get the same page again and I don’t understand why. Any help?
The code now for the navigation:
<?php endwhile; ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link('« previous') ?></div> <div class="alignright"><?php previous_posts_link('Next »') ?></div> <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?> </div></div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php include (TEMPLATEPATH . "/searchform.php"); ?> <?php endif; ?>
-
it is never the code for the navigation that is causing it;
the reason is likely to be the custom query without the pagination parameter:
http://codex.wordpress.org/Function_Reference/query_posts#Pagination_Parameterspaged=2 – show the posts that would normally show up just on page 2 when using the “Older Entries” link. You should set this to get_query_var( ‘paged’ ) if you want your query to work with pagination.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // pagination query_posts('posts_per_page=5&paged=' .$paged);
(keep your other query parameter as they are (does not work in connection with the offset parameter))
Nice work!! In the php there was actually a line that said:
query_posts('posts_per_page=15');
But when I replaced it with your code, everything is working just fine.
Thanks again for the help (y)
Hello,
I am having a similar issue, and I’ve tried adding the “paged” code but it is still not working. I have two loops on my site, please take a look & let me know where I am going wrong… Thank you very much!
Site: shalasrabbithole.com/blog
Loop 1 (large main post)
<?php query_posts( 'cat=-9,-10&showposts=1' ); if (have_posts()) : while (have_posts()) : the_post(); $category = get_the_category(); ?> <div class="wrapper" style="margin-bottom:25px;"> <?php if( get_post_meta( $post->ID, "image_value", true ) ) : ?> <div class="image"> <a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>&w=930&h=500&zc=1" alt="<?php the_title(); ?>" class="img_main" /></a> </div> <?php endif; ?> <div class="post_header"> </div> <div class="post_large"> <div class="headline"> <h1><?php the_title(); ?></h1> </div> <div class="posted"> posted on <?php the_time( 'l F j, Y' ) ?> | in <?php the_category(',') ?> | <?php comments_popup_link(__( '0 Comments' ), __( '1 Comment' ), __( '% Comments' )); ?> </div> <p> <?php the_excerpt(); ?> <a>#more-<?php the_ID(); ?>" rel="bookmark" title="Continue Reading <?php the_title_attribute(); ?>"> Continue Reading →</a> </p> </div> <div class="post_ripped"> </div> </div> <?php endwhile; endif; ?>
Loop 2 (smaller posts, two on each line)
<?php query_posts( 'cat=-9,-10&showposts=10&offset=1' ); if (have_posts()) : $counter = 0; while (have_posts()) : the_post(); $category = get_the_category(); if( $counter % 2 == 0 ) $end = ""; else $end = "last"; ?> <div class="left clearfix"> <?php if( get_post_meta( $post->ID, "image_value", true ) ) : ?> <div style="width:490px;"> <a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo get_post_meta( $post->ID, "image_value", true ); ?>&w=450&h=300&zc=1" alt="<?php the_title(); ?>" class="img_secondary" /></a> </div> <?php endif; ?> <div class="post_header" style="width:95%;"> </div> <div class="post" style="width:83%;"> <div class="headline" style="width:375px;" > <h2><?php the_title(); ?> </h2> </div> <div class="posted2"> <?php the_time('F j, Y') ?> | <?php the_category(',') ?> | <?php comments_popup_link(__( '0 Comments' ), __( '1 Comment' ), __( '% Comments' )); ?> </div> <p> <?php the_excerpt(); ?> <a>#more-<?php the_ID(); ?>" title="Continue Reading <?php the_title_attribute(); ?>" class="color" rel="bookmark">Continue Reading →</a></p> </div> <div class="post_ripped" style="width:95%;"> </div> </div> <?php // Clear the left float to allow for different heights if( $counter % 2 != 0 ) echo'<div style="clear:left;"> </div>'; ?> <?php $counter++; endwhile; endif; ?>
- The topic ‘Navigation blog page: previous – next’ is closed to new replies.