Skip to main content

Forums

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #148037
    Ricky55
    Participant

    Hi Guys

    Struggling to get this working. This code appears on my page-blog.php When the links are clicked the url changes to /page/2/ etc but the posts themselves don’t change. I have some very similar code in my single.php and its working fine. My code is below, what am I doing wrong?

    `

    <section role="main">
    
            <?php $page = get_page_by_title('the blog'); $content = apply_filters('the_content', $page->post_content); echo $content; ?>
    
            <?php $blog_posts = new WP_Query(); $blog_posts->query('showposts=5');
                if ( $blog_posts->have_posts() ) : while ( $blog_posts->have_posts() ) : $blog_posts->the_post(); ?>
    
            <article>
                <?php the_title(); ?>
            </article>
    
            <?php endwhile; ?>
    
            <nav id="post-nav">
                <span class="prev"><?php next_posts_link( '&larr; View Older Posts', $blog_posts->max_num_pages ); ?></span>
                <?php previous_posts_link('<span class="next">' .( 'View more Recent Posts &rarr;' ). '</span>'); ?>
            </nav>
    
            <?php else:  ?>
                <p>Sorry it looks like you need to add some posts to this blog!</p>
            <?php endif; wp_reset_query(); ?>
    
    </section>
    

    `

    #148240
    Ricky55
    Participant

    Found a fix for this just in case anyone ever reads this and requires then same answer. My older posts link wasn’t working as I hadn’t set the paged variable.

    My code looks like this now.

    `

    <img src="<?php print IMAGES; ?>/header-blog.jpg" alt="Blog Header Image" width="999" height="250">
    
    <section role="main">
    
            <?php $page = get_page_by_title('the blog'); $content = apply_filters('the_content', $page->post_content); echo $content; ?>
    
            <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                $blog_posts = new WP_Query('showposts=4' . '&paged='.$paged);
    
                if ( $blog_posts->have_posts() ) : while ( $blog_posts->have_posts() ) : $blog_posts->the_post(); ?>
    
            <article>
                <?php the_title(); ?>
            </article>
    
            <?php endwhile; ?>
    
            <nav id="post-nav">
                <span class="prev"><?php next_posts_link( '&larr; View Older Posts', $blog_posts->max_num_pages ); ?></span>
                <?php previous_posts_link('<span class="next">' .( 'View more Recent Posts &rarr;' ). '</span>'); ?>
            </nav>
    
            <?php else:  ?>
                <p>Sorry it looks like you need to add some posts to this blog!</p>
            <?php endif; wp_reset_query(); ?>
    
    </section>
    

    `

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.