PHP Developer

Tuesday, 31 March 2015

Create Template page to show all posts with pagination

Create Template page to show all posts with pagination


STEP 1.  Upload wordpress simple pagination plugin and activete it (https://wordpress.org/plugins/simple-pagination/)

STEP 2. Copy below code as a template page.

<?php
/*
* Template name: All Posts page
*/

?>

<?php get_header();?>

<div class="pop_cause all_cause">
    <h4>All Posts</h4>

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('posts_per_page=20&post_type=project'.'&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
        <h5><?php the_title();?></h5>
    <?php endwhile; ?>

    <?php if(function_exists('wp_simple_pagination')) { wp_simple_pagination(); }  ?>  //This function is use to show pagination and is exist in Simple Pagination Plugin
    <?php $wp_query = null; $wp_query = $temp;?>
</div> 

<?php get_footer(); ?>

No comments:

Post a Comment