WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Previous/Next buttons not working (7 posts)

  1. ddayco
    Member
    Posted 3 years ago #

    Hello, my site has pages that display posts only from a certain category. My problem is when you click "previous entries" it goes to page 2 but still displays the same posts as before. Can anyone help?

    <?php
    /*
    Template Name: Blog
    */
    ?>
    
    <?php get_header(); ?>
    
    <h1>Blog</h1>
    
    <div class="content">
    
    <?php
    query_posts('category_name=Blog');
    global $more;
    $more = 0;
    ?>		
    
    <?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
    				<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    
    				<?php if (get_post_meta($post->ID, 'post_image_value', true) ) { ?>
        			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php echo get_post_meta($post->ID, "post_image_value", $single = true); ?>" alt="<?php the_title(); ?>" class="portfolioimg" /></a>
    				<?php } ?>
    
    				<div class="entry">
    					<?php the_content('Continue Reading &rarr;'); ?>
    				</div>
    
    				<p class="meta">Written on <?php the_time('F jS, Y') ?>. <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></p>
    			</div>
    
    		<?php endwhile; ?>
    
    <div class="navigation">
    		<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
    
            <div class="alignleft"><?php next_posts_link('&larr; Previous Entries') ?></div>
            <div class="alignright"><?php previous_posts_link('Next Entries &rarr;') ?></div>
            <?php } ?>
    		</div>
    	</div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  2. Big Bagel
    Member
    Posted 3 years ago #

    Maybe this would work:

    query_posts('category_name=Blog&paged=' . get_query_var( 'page' ) );

  3. ddayco
    Member
    Posted 3 years ago #

    Thank you for the reply, unfortunately this produces the same result.

  4. Big Bagel
    Member
    Posted 3 years ago #

    The codex page for query_posts has a few good tips for usage in a template. If I read it right, when used in a template, it ignores parameters passed through the url (such as what page it's on). Try this:

    global $query_string;
    query_posts( $query_string . '&category_name=Blog&paged=' . get_query_var( 'page' ) );

    Hopefully that works (I've never had to do much experimenting with this in the past so my advice might be lacking).

    Edit:
    It might also be easier to create an entirely new query rather than use query_posts.

  5. ddayco
    Member
    Posted 3 years ago #

    Thanks, but that's not working either, it 'causes it to pull in some other content, just a few lines of gibberish where the blog post should be. I'm not even sure where that content is from.

    In terms of creating a new query, I wouldn't really know how do to that. I don't know much php, I'm just trying to fix a template that I downloaded, the author is no longer supporting it.

    This is the site if that helps at all. http://daviddayco.ca/?page_id=12
    The blog and recent work sections both display posts in specific categories and both have the same issue.

    Thanks!

  6. Big Bagel
    Member
    Posted 3 years ago #

    Ah, sorry. Now that I can see it's using the "paged" parameter in the url, try using "paged" instead of "page":

    query_posts('category_name=Blog&paged=' . get_query_var( 'paged' ) );

    My second suggestion would never work as it is (I copy/pasted from the codex without thinking). Sorry for making you try all sorts of things. If this doesn't work I'll copy the template above and test it my own installation.

  7. ddayco
    Member
    Posted 3 years ago #

    It works! Thanks so much for you help, I really appreciate it.

Topic Closed

This topic has been closed to new replies.

About this Topic