• I have created a custom theme for my website and have named it simplepv. I have a custom home page and a separate page to show all my blog posts. But I can’t integrate pagination feature to my custom blogs page. I have searched it over the net and among the forums but couldn’t find a solution to my problem. I don’t have any function for pagination in my function.php, don’t I need to add one? I have placed my code below, Any help is really appreciated.

    <?php
    /*
    Template Name: Blogs
    */
    ?>
    <?php get_header(); ?>
    	<section>
    		<?php $my_query = "showposts=4"; $my_query = new WP_Query($my_query); ?>
    		<?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php the_title() ?>
                <?php the_excerpt('') ?>
    		<?php endwhile; // end of one post ?>
            <?php endif; //end of loop ?>
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<?php endwhile; endif; ?>
    	</section>
        <div style="height:10px;">&nbsp;</div>
    </div>
    <?php get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • <?php if (function_exists(“pagination”)) {
    pagination($additional_loop->max_num_pages);
    } ?>

    Thread Starter anant.nigam

    (@anantnigam)

    thanks, but where do i need to add this code?

    Moderator keesiemeijer

    (@keesiemeijer)

    Try adding one of these pagination functions to the template:
    https://codex.www.ads-software.com/Pagination#Function_Reference

    For a static front page you need to add the “paged” query variable to the query
    https://codex.www.ads-software.com/Pagination#static_front_page

    Try it with this:

    <?php
    /*
    Template Name: Blogs
    */
    ?>
    <?php get_header(); ?>
    	<section>
    
    		<?php
    		if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
    		elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
    		else { $paged = 1; }
    		$my_query = new WP_Query('posts_per_page=4&paged='.$paged); ?>
    		<?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php the_title() ?>
                <?php the_excerpt('') ?>
    		<?php endwhile; // end of one post ?>
    		<div class="nav-previous"><?php next_posts_link(); ?></div>
    		<div class="nav-next"><?php previous_posts_link(); ?></div>
            <?php endif; //end of loop ?>
    
    	</section>
        <div style="height:10px;">&nbsp;</div>
    </div>
    <?php get_footer(); ?>

    <?php
    /*
    Template Name: Blogs
    */
    ?>
    <?php get_header(); ?>
    	<section>
    		<?php $my_query = "showposts=4"; $my_query = new WP_Query($my_query); ?>
    		<?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
    			<?php the_title() ?>
                <?php the_excerpt('') ?>
    		<?php endwhile; // end of one post ?>
            <?php endif; //end of loop ?>
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<?php endwhile; endif; ?>
    <?php if (function_exists("pagination")) {
    pagination($additional_loop->max_num_pages);
    } ?>
    	</section>
        <div style="height:10px;">?</div>
    </div>
    <?php get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Include pagination in my custom blogs page’ is closed to new replies.