• Hi all,

    I’m working on this site and have created a custom template for the homepage

    http://theluckystrike.co.uk/tfc/

    Below the “Featured” box I want to pull in just the posts from the “News” category. I’ve got the loop working and pulling in 6 posts. Below the posts I’ve got WP-PageNavi installed, but going to page 2 returns the same posts as the first page

    Could anyone lend a hand please?

    thanks
    Mark

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter markj81

    (@markj81)

    `<!– News –>
    <div class=”header-box”><h1><a href=”/tfc/news/”>NEWS</a></h1></div>
    <div class=”blog-box”>

    <?php if (have_posts()) : ?>

    <?php query_posts(‘category_name=News&showposts=6’); ?>

    <?php while (have_posts()) : the_post(); ?>

    <!– The post –>
    <div class=”post” id=”post-<?php the_ID(); ?>”>

    <!– The title –>
    <div class=”title”><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></div>

    <!– Meta details –>
    <div class=”metaline”>Posted on <?php the_time(‘F jS, Y’) ?> in <? the_category() ?>  |  <?php the_tags() ?></div>

    <!– Thumbnail –>
    <div class=”thumbnail”><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_post_thumbnail(‘thumbnail’); ?></a></div>

    <!– The excerpt –>
    <div class=”entry”>
    <!– Excerpt limited to 25 words –>
    <?php the_excerpt(25); ?>
    <p class=”readmore”><a href=”<?php the_permalink() ?>”>Read more</a></p>
    </div>

    <div class=”clear”></div>
    </div>

    <div class=”clear”></div>
    <div class=”break”></div>
    <!– end post –>

    <?php endwhile; ?>
    </div>

    <div class=”page-navi”>
    <?php wp_pagenavi(); ?>
    </div>
    </div>
    <?php endif; ?>

    when you use query_posts you have to account for pagination in the query

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array(
    	'category_name' => 'News',
             'posts_per_page' => 6,
             'paged'=>$paged,
            ));
    ?>

    also, showposts is deprecated, posts_per_page is preferred

    Thread Starter markj81

    (@markj81)

    Thanks. So I’d replace with the following?

    <?php if (have_posts()) : ?>
    
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array(
    	'category_name' => 'News',
             'posts_per_page' => 6,
             'paged'=>$paged,
            ));
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with custom template – won't display the next page correctly’ is closed to new replies.