• John

    (@jtrabelsi)


    Hello, I have this simple code that shows last 5 posts.
    But If I have more it doesn’t show the “older post” button. ??

    <?php query_posts(‘showposts=5'); global $more; $more = 0; ?>
    
    <?php while (have_posts()) : the_post(); ?>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    	<div class="more_home">
            <div class="more_title"><?php the_title(); ?></div>
                <?php the_content(''); ?>
        	</div>
    </div>
    <?php endwhile;?>
    <?php get_footer(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • LonelyPlanet

    (@lonelyplanet)

    If you want pagination then you can use a plugin such as wp pagenavi. Not sure about your exact question but wp pagenavi handles the pagination of post pages very well.

    Thread Starter John

    (@jtrabelsi)

    Thank you for your reply!
    I have added this but it shows the same posts on every pages ??

    <?php if(function_exists('wp_pagenavi')) : ?>
    
    		<?php wp_pagenavi(); ?>
    
    	<?php else : ?>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
    
          <nav class="oldernewer">
            <div class="older">
              <?php next_posts_link('&laquo; Older Entries') ?>
            </div>
    
            <div class="newer">
              <?php previous_posts_link('Newer Entries &raquo;') ?>
            </div>
          </nav>
    
        <?php endif; ?>
      <?php endif; ?>
    Thread Starter John

    (@jtrabelsi)

    Here is the full code :

    <?php query_posts('showposts=2'); global $more; $more = 0; ?>
    
    <?php while (have_posts()) : the_post(); ?>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>    
    
    	<div class="post-info">
    	<b><?php the_time('l, d F Y H:i'); ?></b>
    
            <div class="post-block">
                <?php the_content(); ?>
        	</div>
    </div>
    	</div>
    
    <?php endwhile;?>
    
    <?php if(function_exists('wp_pagenavi')) : ?>
    
    		<?php wp_pagenavi(); ?>
    
    	<?php else : ?>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
    
          <nav class="oldernewer">
            <div class="older">
              <?php next_posts_link('&laquo; Older Entries') ?>
            </div>
    
            <div class="newer">
              <?php previous_posts_link('Newer Entries &raquo;') ?>
            </div>
          </nav>
    
        <?php endif; ?>
      <?php endif; ?>
    wspencer

    (@wspencer)

    Try something like this…..

    <?php query_posts(cat=12&posts_per_page=10&paged=' .$paged); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>    
    
    	<div class="post-info">
    	<b><?php the_time('l, d F Y H:i'); ?></b>
    
            <div class="post-block">
                <?php the_content(); ?>
        	</div>
    </div>
    	</div>
    
    <?php endwhile;?>
    
    <?php wp_pagenavi(); ">

    the query_posts function accepts several arguments…one of which is posts_per_page. I threw in the cat=12 as an example of specifying a category. Try going with the posts_per_page rather than showposts and see if that works. I do something similar on my own site.

    Thread Starter John

    (@jtrabelsi)

    WORKS GREAT!
    THANK YOU!

    with one tiny change, was missing a ” ‘ ” before “cat=12”

    Here is the code if it can help someone:

    – Showing 10 last post.
    – With navigation to older entries.

    (thanks to wspencer for this code.)

    <?php query_posts('posts_per_page=10&paged=' .$paged); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            <h2><?php the_title(); ?></h2>    
    
    	<div class="post-info">
    	<b><?php the_time('l, d F Y H:i'); ?></b>
    
            <div class="post-block">
                <?php the_content(); ?>
        	</div>
    </div>
    	</div>
    
    <?php endwhile;?>
    
    <?php wp_pagenavi(); ">
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add paging on the bottom’ is closed to new replies.