functions - WordPress not showing pagination links

admin2025-01-08  5

In my WordPress Index.html I am pulling out the 3 latest posts by using

<?php query_posts('posts_per_page=3') ?>

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

   //rest of the post related data

<?php endwhile; wp_reset_query();  ?>
<?php do_action('show_navigation');

after that I want to fetch the next 3 or previous 3 posts and for this I am trying

if ( ! function_exists( 'theme_content_navigation' ) ) {
    function theme_content_navigation( ) {
        global $wp_query;

        if ( $wp_query->max_num_pages > 1 ) { ?>
            <nav class="navigation" role="navigation">
                <div class="nav-previous"><?php next_posts_link( '<' ); ?></div>
                <div class="nav-next"><?php previous_posts_link( '>' ); ?></div>
            </nav>
        <?php 
        }
    }
}



add_action('show_navigation', 'theme_content_navigation');

this code in functions.php.

Right now I have 4 posts and three of them are displaying in my index.php but I am unable to see the navigation links to fetch next posts and replace the existing ones in index.php. Kindly suggest me how to fetch next or previous posts.

In my WordPress Index.html I am pulling out the 3 latest posts by using

<?php query_posts('posts_per_page=3') ?>

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

   //rest of the post related data

<?php endwhile; wp_reset_query();  ?>
<?php do_action('show_navigation');

after that I want to fetch the next 3 or previous 3 posts and for this I am trying

if ( ! function_exists( 'theme_content_navigation' ) ) {
    function theme_content_navigation( ) {
        global $wp_query;

        if ( $wp_query->max_num_pages > 1 ) { ?>
            <nav class="navigation" role="navigation">
                <div class="nav-previous"><?php next_posts_link( '<' ); ?></div>
                <div class="nav-next"><?php previous_posts_link( '>' ); ?></div>
            </nav>
        <?php 
        }
    }
}



add_action('show_navigation', 'theme_content_navigation');

this code in functions.php.

Right now I have 4 posts and three of them are displaying in my index.php but I am unable to see the navigation links to fetch next posts and replace the existing ones in index.php. Kindly suggest me how to fetch next or previous posts.

Share Improve this question asked Aug 31, 2015 at 16:54 Faisal NaseerFaisal Naseer 1131 gold badge1 silver badge7 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

solved my problem by removing

<?php query_posts('posts_per_page=3') ?>

and tried limiting posts from Settings->Reading. Thanks

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736268628a1289.html

最新回复(0)