Pagination issue with blog
Posted: Tue Nov 14, 2006 7:40 am
feyd | Please use
This page is called pagination.php and i am including it into my blog page like so
I am calling the function like this:
There is a function already on my blog page created by dreamweaver to count how many rows are in the table:
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.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
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:Code: Select all
<?php
### Function: Page Navigation: Normal Paging
function wp_pagenavi($before=' ', $after=' ', $prelabel='«', $nxtlabel='»') {
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().'">« 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 »</a>';
}
echo "$after</b>";
}
}
}
?>Code: Select all
<?php require_once('pagenavi.php'); ?>Code: Select all
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>Code: Select all
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;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.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]