• Resolved ddayco

    (@ddayco)


    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(); ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Maybe this would work:

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

    Thread Starter ddayco

    (@ddayco)

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

    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.

    Thread Starter ddayco

    (@ddayco)

    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. https://daviddayco.ca/?page_id=12
    The blog and recent work sections both display posts in specific categories and both have the same issue.

    Thanks!

    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.

    Thread Starter ddayco

    (@ddayco)

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Previous/Next buttons not working’ is closed to new replies.