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 971343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:57:00+00:00 2026-05-16T02:57:00+00:00

This a template page in my wordpress (have removed html), it pulls out the

  • 0

This a template page in my wordpress (have removed html), it pulls out the posts from my wordpress database. I want to paginate it but have no idea! 🙁

I wan’t to get something like this

<< First Prev 1 2 3 4 Next Last >>

       <?php
         $postslist = get_posts('numberposts=10&order=ASC');
         foreach ($postslist as $post) : 
            setup_postdata($post);
    ?>

      <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?>   </a></li>
     <li><?php the_excerpt(); ?></li><br/><hr/>

     <?php endforeach; ?>
  • 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-05-16T02:57:01+00:00Added an answer on May 16, 2026 at 2:57 am

    Here’s a pagination class I use:

    <?php
    
    class sitePagination{
    
        public $currentPage;
        public $perPage;
        public $totalRecords;
    
        public function __construct($page = 1,$per_page = 2, $total_records = 0){
            $this->currentPage = (int)$page;
            $this->perPage = (int)$per_page;
            $this->totalRecords = (int)$total_records;  
        }
    
        public function totalPages(){
            return ceil($this->totalRecords / $this->perPage);
        }
    
        public function previousPage(){
            return $this->currentPage - 1;
        }
    
        public function nextPage(){
            return $this->currentPage + 1;
        }
    
        public function previousPageExists(){
            return $this->previousPage() >= 1 ? true : false; 
        }
    
        public function nextPageExists(){
            return $this->nextPage() <= $this->totalPages() ? true : false; 
        }
    
        public function offset(){
            return ($this->currentPage - 1) * $this->perPage;
        }
    
    }
    
    ?>
    

    And then in the page.html, I used this:

    //include the paginate class. I put it in the theme folder
        include("paginate.php");
    
        //This is the SQL Query to get the number of rows I have
        $count = "SELECT COUNT(*) FROM $wpdb->blogs WHERE site_id = $wpdb->siteid AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00'"; 
    
        $number =  mysql_query($count);
        $row = mysql_fetch_array($number);
        $num_rows = array_shift($row);
    
        //Define some variable to hold our pagination settings
        $page = !empty($_GET['current_page']) ? (int)$_GET['current_page'] : 1;
        $perPage = 5;
        $paginate  =  new sitePagination($page,$perPage,$num_rows);
    
        //This is the actual SQL Query to fetch the Data from Database
        $query = $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT {$perPage} OFFSET {$paginate->offset()}", $wpdb->siteid );
        //echo "query is $query<br/>";
    
        $terms = $wpdb->get_results($query,ARRAY_A);
        echo "<ul>";
    
        foreach($terms as $detail)
        {
            //$cat_parent = get_category($detail->parent);
            //Had to use the $cat_parent to build the link
            //if some has a better idea, would be nice
            echo "<li style='font-size:1.3em;'><a href='http://".$detail[ 'domain' ].$detail['path']."'>".get_blog_option( $detail['blog_id'], 'blogname' )."</a></li>";
        }
    
        // The Fun starts here, all the code below will generate our dynamic page number
        // The container class is the same as WP PAGENAVI
        // I'm using a custom pagination class I created
        echo "</ul>";
    
        //echo "<span class='pages'>Page {$page} of {$paginate->totalPages()}</span>";
        if($paginate->totalPages() > 1){
            if($paginate->previousPageExists()){
                echo '<a href="?cat='.$cat_parent->term_id.'&current_page='.$paginate->previousPage().'">&laquo; Previous</a>';
            }
        }
        if(ceil($paginate->totalPages()) > 1){
            for($i=1;$i < ceil($paginate->totalPages()) + 1;$i++){
                if($page == $i)
                    echo '<span class="current"> '.$i.' </span>';
                else
                    echo '<a href="'.$cat_parent->slug.'/?current_page='.$i.'"> '.$i.' </a>';
    
            }
        }
    
        if($paginate->totalPages() > 1){
            if($paginate->nextPageExists()){
                echo '<a href="?cat='.$cat_parent->term_id.'&current_page='.$paginate->nextPage().'">Next &raquo;</a>';
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This should answer your question... "The forms authentication ticket not… May 17, 2026 at 1:57 am
  • Editorial Team
    Editorial Team added an answer update. The way to ignore specific exceptions is to catch… May 17, 2026 at 1:57 am
  • Editorial Team
    Editorial Team added an answer I believe it should be possible; but you will probably… May 17, 2026 at 1:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have created a category template in Wordpress for all posts that are in
I have a page template where I want to list entries for each child
I have a wordpress blog. I made a custom page-template that allows users to
How do i paginate this? It's a code in wordpress template I'm using to
I'm pretty new to WordPress but have spent some 50 odd hours studying up
I have a wordpress site with a large number of pages, each page represent
I have a static page set up as my front page for Wordpress. I
I have a static page set as front page in Wordpress, instead of default
This is the page, its a wordpress powered site: http://bit.ly/9oJXWV You select some value,
In the default Wordpress template, there is this in header.php . <body <?php body_class();

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.