- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
August 24, 2013 at 12:50 pm #148037
Ricky55
ParticipantHi 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( '← View Older Posts', $blog_posts->max_num_pages ); ?></span> <?php previous_posts_link('<span class="next">' .( 'View more Recent Posts →' ). '</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>
`
August 27, 2013 at 9:31 am #148240Ricky55
ParticipantFound 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( '← View Older Posts', $blog_posts->max_num_pages ); ?></span> <?php previous_posts_link('<span class="next">' .( 'View more Recent Posts →' ). '</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>
`
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘Back End’ is closed to new topics and replies.