Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8837417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:43:07+00:00 2026-06-14T09:43:07+00:00

Sorry, if I sound a bit naive.. I am a decent PHP developer and

  • 0

Sorry, if I sound a bit naive..
I am a decent PHP developer and have been trying to learn wordpress recently.
Can anyone tell me or point to a tutorial that tells me the best way to show posts on a custom template with pagination ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:43:09+00:00Added an answer on June 14, 2026 at 9:43 am

    Since occasionally(or maybe most of the time, I’m not sure) you can get permalink conflicts and therefore unexpected 404 pages if you just make a custom query_posts() and then you add a pagination, with links to page-slug/page/2, page-slug/page/3, page-slug/page/n, I usually set the pagination as a $_GET parameter.

    Here is an example code for that:

    <?php
    /*  
        Template Name: Custom Loop Template
    */
    get_header();
    
    // Set up the paged variable
    $paged = ( isset( $_GET['pg'] ) && intval( $_GET['pg'] ) > 0 )? intval( $_GET['pg'] ) : 1;
    query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'posts_per_page' => 1 ) );
    
    ?>
    <?php if ( have_posts() ) : ?>
        <?php while( have_posts() ) : the_post(); ?>
            <div id="post-<?php echo $post->ID; ?>" <?php post_class(); ?>>
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <div class="post-excerpt">
                    <?php the_excerpt(); ?>
                </div>
            </div>
        <?php endwhile; ?>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
            <div class="pagination">
                <?php for ( $i = 1; $i <= $wp_query->max_num_pages; $i ++ ) { 
                    $link = $i == 1 ? remove_query_arg( 'pg' ) : add_query_arg( 'pg', $i );
                    echo '<a href="' . $link . '"' . ( $i == $paged ? ' class="active"' : '' ) . '>' . $i . '</a>';
                } ?>
            </div>
        <?php endif ?>
    <?php else : ?>
        <div class="404 not-found">
            <h3>Not Found</h3>
            <div class="post-excerpt">
                <p>Sorry, but there are no more posts here... Please try going back to the <a href="<?php echo remove_query_arg( 'pg' ); ?>">main page</a></p>
            </div>
        </div>
    <?php endif;
    
    // Make sure the default query stays intact
    wp_reset_query();
    
    get_footer();
    ?>
    

    This will create a custom Page template, called Custom Loop Template and will display the latest posts, 1 per page. It will have a basic pagination at the bottom starting from 1 to the maximum number of pages for that query.

    Of course, that’s just a pretty basic example, but it should be enough for you to figure the rest out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys sorry if sounds a little bit naive... In an activity I have one
I'm sorry if this will sound like a dumb question but I just can't
Sorry this is going to sound like a ridiculous question but can methods (not
I have a Android Actionscript project that I am trying to incorporate sound in,
Sorry I'm a bit new to this so just trying to get my head
Sorry if the title sounds a bit vague. Stackoverflow posting newbie here. I have
Sorry if this question will sound too chaotic, feel free to edit it. I
This is going to sound too silly / too basic - sorry about that,
Hi I am completely new to Java, so sorry if my question may sound
Sorry if the title sounds confusing - but this is what I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.