How to add posts with navigation in home.php?

I have a theme I'm building and I'm trying to work on the homepage from home.php. I already have my listing of latest articles generating, but I want the page navigation to show up at the bottom for the next and/or previous set of articles. Ideally, some sort of lazy load too, but at the moment, I just want to understand how to do the page navigation part.

I'm having trouble finding articles on how to do this without "add THIS plugin" or "use THIS theme".

Here's what I already have to generate my articles section:

<section id="articles" class="container">

    $grid_posts = get_posts( array(
        'posts_per_page' => 12
    ) );

    if ( $grid_posts ) {
        foreach ( $grid_posts as $post ) :
            setup_postdata( $post ); ?>
              if ( has_post_thumbnail() ) : get_template_part('template-parts/posts-grid', 'image');
              else : get_template_part('template-parts/posts-grid', 'default');


I just want to find a resource that shows me how to either "load more articles" on that page or show the "next/previous page" navigation.


1 answer

  • answered 2019-08-13 15:36 user127091

    You're looking for wp_link_pages

            wp_link_pages( array(
                'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'test' ),
                'after'  => '</div>',
            ) );

    For those kind of questions and to get a basic understanding, it's also always worth at least looking into a "template theme" like _s In your case, the file to look at would be this one