PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 9, 2022

[FIXED] Why does page navigation not work here?

 July 09, 2022     categories, navigation, posts, wordpress     No comments   

Issue

    <?php
/**
* Template Name: Blog page
* Description: The blog page
*/
get_header(); ?>


<?php
$args = array( 'numberposts' => 3 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
<div class="postblog">
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>

    <span class="postdetails">
    <?php the_time ('j F, Y'); ?>&nbsp;&nbsp;&nbsp;<span class="bullet">&bull;</span>&nbsp;&nbsp;&nbsp;Posted in:&nbsp;<?php the_category(', '); ?>
    </span>

    <?php the_content(); ?>

    <div class="fb">
    <?php if(function_exists("wpfblike")) echo wpfblike(); ?>
    </div>

    </div>

<?php endforeach; ?>


</div>
<?php get_footer(); ?>

Whenever I try to use WP_Paginate or Pagenavi with this, it refuses to show up, no matter what I try to use I cannot get page navigation. I have 5 posts and only three are showing (as per the code above) so how do I get to the other two?


Solution

Have you tried using next_posts_links and previous_posts_links?

<?php
$page = (get_query_var('paged')) ? get_query_var('paged') : 1; 
query_posts("showposts=3&paged=$page");
?>
<?php while (have_posts()) : the_post(); ?>
// display your post
<?php endwhile; ?>
// display navigation
<div class="navigation">
<div class="alignleft"><?php next_posts_link('&larr; Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries &rarr;') ?></div>
</div>


Answered By - Cyclonecode
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing