Jump to content

Pagination issue with blog


lip9000

Recommended Posts

Ive set up a blog page in my website using dreamweaver and im trying to setup pagination so it displays each page of records that exists like so:
Pages (4): [1] 2 3 4 »

There is a plugin for Word Press that you can install called wp-pagenavi, and it contains a pagination script (for those of you who arent familiar with it). I'm trying to use this script within my own blog so that i can use the pagination in that but I'm not sure how i need to set it up.

The pagination script looks like this:
php:
[code]<?php

### Function: Page Navigation: Normal Paging
function wp_pagenavi($before=' ', $after=' ', $prelabel='&laquo;', $nxtlabel='&raquo;') {
        global $request, $posts_per_page, $wpdb, $paged;
        $pages_to_show = 5;
        $half_pages_to_show = round($pages_to_show/2);
        if (!is_single()) {
                if (get_query_var('what_to_show') == 'posts') {
                        preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
                        //preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
                        $fromwhere = $matches[1];
                        $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
                        $max_page = ceil($numposts /$posts_per_page);
                } else {
                        $max_page = 999999;
                }
                if(empty($paged)) {
                        $paged = 1;
                }
                if($max_page > 1) {
                        echo "$before Pages ($max_page): <b>";
                        if ($paged >= ($pages_to_show-1)) {
                                echo '<a href="'.get_pagenum_link().'">&laquo; First</a> ... ';
                        }
                        previous_posts_link($prelabel);
                        for($i = $paged - $half_pages_to_show; $i  <= $paged + $half_pages_to_show; $i++) {
                                if ($i >= 1 && $i <= $max_page) {
                                        if($i == $paged) {
                                                echo "[$i]";
                                        } else {
                                                echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> ';
                                        }
                                }
                        }
                        next_posts_link($nxtlabel, $max_page);
                        if (($paged+$half_pages_to_show) < ($max_page)) {
                                echo ' ... <a href="'.get_pagenum_link($max_page).'">Last &raquo;</a>';
                        }
                        echo "$after</b>";
                }
        }
}

?>[/code]


This page is called pagination.php and i am including it into my blog page like so php:
[code]<?php require_once('pagenavi.php'); ?> [/code]

I am calling the function like this: php:
[code]<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>[/code]


There is a function already on my blog page created by dreamweaver to count how many rows are in the table:php:
[code]if (isset($_GET['totalRows_rsPosts'])) {
  $totalRows_rsPosts = $_GET['totalRows_rsPosts'];
} else {
  $all_rsPosts = mysql_query($query_rsPosts);
  $totalRows_rsPosts = mysql_num_rows($all_rsPosts);
}
$totalPages_rsPosts = ceil($totalRows_rsPosts/$maxRows_rsPosts)-1;[/code]


So i know that i somehow need to replace the SELECT statement in the pagenavi script with the variable thats already assigned to mysql_num_rows.

When i try run the blog page, no navigation appears at all, so something is definately wrong, i just dont know what. (im fairly new to PHP).

Can anyone help me? Many thanks.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.