• I have a custom loop that queries posts, I want to show only 10 posts, but at the bottom link to all posts that matche the query. Is there a good way to do that?

    The query:

    $args = array(
    	'category__and' => array(5739,50),
    	'posts_per_page' => 2,
    	'orderby' => 'date'
        );

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • You can use pagination by appending a page number to the url, eg. https://example.com/blog?paged=1.

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    $args = array(
        'category__and' => array( 5739, 50 ),
        'posts_per_page' => 2,
        'orderby' => 'date',
        'paged' => $paged,
    );
    $my_posts = get_posts( $args );
    
    // Links to page 1 to 3
    echo '<a href="https://example.com/blog?paged=1>Page 1</a>';
    echo '<a href="https://example.com/blog?paged=2>Page 2</a>';
    echo '<a href="https://example.com/blog?paged=3>Page 3</a>';

    Note the added paged argument in the query. If it is 2, then the 2nd page of posts will be retrieved. You can read up more at https://codex.www.ads-software.com/Class_Reference/WP_Query#Pagination_Parameters

Viewing 1 replies (of 1 total)
  • The topic ‘How to set link to the other posts inside a loop’ is closed to new replies.