Support » Fixing WordPress » Make own blog page template with pagination

  • Hi WP developers.

    Trying to get my first WordPress with bootstrap 3 running. I’m stuck in the pagination of my template that won’t function. Someone who please can help. Thanks /peter.

    The code for the template.

    Template Name: Rompa
    */ ?>

    <!– HUVUD ——————————————————————————————->

    <?php get_header(); ?>

    <h1 class=”tunn grey” style=”clear: both;”><?php the_title(); ?></h1>

    <div class=”blogg col-xs-12 col-sm-10 col-md-10″>
    $args = array( ‘posts_per_page’ => 2 );
    $lastposts = get_posts( $args );
    foreach ( $lastposts as $post ) :
    setup_postdata( $post ); ?>

    <div class=”info col-xs-5 col-sm-2 col-md-2″>
    <div class=”blogdate col-xs-0 col-sm-0 col-md-0″>
    <p class=”post-day”><?php the_time(‘j’) ?> </p>
    <p class=”post-month”><?php the_time(‘F’) ?> </p>
    <p class=”post-year”><?php the_time(‘Y’) ?> </p>
    <div class=”post col-xs-12 col-sm-10 col-md-10″><h1 class=”grey”>“><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <div class=”tunn”></div>
    <?php endforeach; wp_reset_postdata(); ?>
    <!– Add the pagination functions here. –>
    <?php posts_nav_link(); ?>
    <div class=”blogg col-xs-12 col-sm-12 col-md-2 pull-right”>
    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The posts_nav_link() function is not meant to provide pagination of multiple posts, but rather of a single post divided into multiple pages. You probably need previous_posts_link() and next_posts_link().

    However, if you are truly trying to have the blog page use a template, that will not work either. The blog page ignores templates as explained in this Codex article:

    You can create a home.php file to show a custom blog page. You should create a Child theme to make your changes. If you do not, all of your changes will be lost if you update your theme.

    I´ve now tried a different way by a WP_query. But if you say its not possible with templates I´ve to think a different way. I´ve to add that I have not chosen any page for the blog in the setting of reading screen. If it matters?

    Template Name: Blog3
    <?php $args = array('');
    $pages = get_pages($args);?>
    <?php // The Query
    $query1 = new WP_Query( $args );
    <?php // The Loop
    while ( $query1->have_posts() ) {
    	echo '<h1>' . get_the_title() . '</h1>';
    	echo '<p>' . the_excerpt() . '</p>';
    // get_next_posts_link() usage with max_num_pages
    echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages );
    echo get_previous_posts_link( 'Newer Entries' );
    <?php /* Restore original Post Data
     * NB: Because we are using new WP_Query we aren't stomping on the
     * original $wp_query and it does not need to be reset.

    You should create a Page and choose it as the Blog page. Then, instead of creating a template, create a home.php file. But, you should do that in a child theme or else your changes will be lost if you update the theme.

    Thanks for your support in this issue, that has coasted a lot of frustation and made my hair turn grey . I´ve tried with your suggestion, but the links didn´t work anyway.

    But this solved the problem for me

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make own blog page template with pagination’ is closed to new replies.