Convert script into google like pagination

Website

Supreme Member
Joined
Feb 8, 2008
Messages
1,291
Reaction score
287
I have this RSS parsing code and it paginates , but only uses 'next' and 'previous' links

I want it to look something like this: http://www.crankberryblog.com/2009/simple-dynamic-php-sliding-pagination

I'll pay to have this done

code:

Code:
<?php

require_once('simplepie.inc');



// Set your own configuration options as you see fit.

$feed = new SimplePie();

$feed->set_feed_url(array(

link1

link2

.....

));

$success = $feed->init();







// Make sure the page is being served with the right headers.

$feed->handle_content_type();



// Set our paging values

$start = (isset($_GET['start']) && !empty($_GET['start'])) ? $_GET['start'] : 0; // Where do we start?

$length = (isset($_GET['length']) && !empty($_GET['length'])) ? $_GET['length'] : 5; // How many per page?

$max = $feed->get_item_quantity(); // Where do we end?



// When we end our PHP block, we want to make sure our DOCTYPE is on the top line to make

// sure that the browser snaps into Standards Mode.

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "\">



<html xmlns="" xml:lang="en-US" lang="en-US">

<head>

<title>SimplePie: Demo</title>



<link rel="stylesheet" href="styles.css" type="text/css" media="screen, projector" />



</head>



<body>

<div id="site">

<?php

// If we have an error, display it.

if ($feed->error())

{

echo '<div class="sp_errors">' . "\r\n";

echo '<p>' . htmlspecialchars($feed->error()) . "</p>\r\n";

echo '</div>' . "\r\n";

}

?>



<?php if ($success): ?>

<?php

// get_items() will accept values from above.

foreach($feed->get_items($start, $length) as $item):

$feed = $item->get_feed();

?>



<div class="chunk">



<h4><?php if ($item->get_permalink()) echo '<a href="' . $item->get_permalink() . '">'; echo $item->get_title(true); if ($item->get_permalink()) echo '</a>'; ?></h4>



<p class="footnote">Source: <a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a> | <?putenv("TZ=US/Pacific"); echo $item->get_date('j M Y | g:i a'); ?></p>



</div>



<?php endforeach; ?>

<?php endif; ?>



<?php

// Let's do our paging controls

$next = (int) $start + (int) $length;

$prev = (int) $start - (int) $length;



// Create the NEXT link

$nextlink = '<a href="?start=' . $next . '&length=' . $length . '">Next »</a>';

if ($next > $max)

{

$nextlink = 'Next »';

}



// Create the PREVIOUS link

$prevlink = '<a href="?start=' . $prev . '&length=' . $length . '">« Previous</a>';

if ($prev < 0 && (int) $start > 0)

{

$prevlink = '<a href="?start=0&length=' . $length . '">« Previous</a>';

}

else if ($prev < 0)

{

$prevlink = '« Previous';

}



// Normalize the numbering for humans

$begin = (int) $start + 1;

$end = ($next > $max) ? $max : $next;

?>



<p>Showing <?php echo $begin; ?>–<?php echo $end; ?> out of <?php echo $max; ?> | <?php echo $prevlink; ?> | <?php echo $nextlink; ?> | <a href="<?php echo '?start=' . $start . '&length=5'; ?>">5</a>, <a href="<?php echo '?start=' . $start . '&length=10'; ?>">10</a>, or <a href="<?php echo '?start=' . $start . '&length=20'; ?>">20</a> at a time.</p>

</div>



</body>

</html>
 
There are a ton of php classes to do this. Are you a developer? if not, what are you offering to get this completed?
 
So how hard would this be to do? How many hours of work?
 
Are you pulling the data from a database? It "should" be somewhere around an hour - max.
 
Are you pulling the data from a database? It "should" be somewhere around an hour - max.

Actually, I dug up a function that should work with your RSS aggregator (Simple Pie) - so i would say.. oooooh.... 5 min :D

Code:
[COLOR=#000000][COLOR=#007700]function [/COLOR][COLOR=#0000bb]pagination[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$total[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$limit[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$current_page[/COLOR][COLOR=#007700],[/COLOR][COLOR=#0000bb]$extra[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]''[/COLOR][COLOR=#007700]){ 
         
        [/COLOR][COLOR=#0000bb]$numofpages[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]ceil[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$total [/COLOR][COLOR=#007700]/ [/COLOR][COLOR=#0000bb]$limit[/COLOR][COLOR=#007700]); 
        if([/COLOR][COLOR=#0000bb]$numofpages [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#dd0000]'1'[/COLOR][COLOR=#007700]){ 
             
            [/COLOR][COLOR=#0000bb]$range[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]10[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#0000bb]$range_min[/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]% [/COLOR][COLOR=#0000bb]2 [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700])?([/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]/ [/COLOR][COLOR=#0000bb]2[/COLOR][COLOR=#007700]) - [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]:([/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) / [/COLOR][COLOR=#0000bb]2[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#0000bb]$range_max[/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]% [/COLOR][COLOR=#0000bb]2 [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]0[/COLOR][COLOR=#007700])?[/COLOR][COLOR=#0000bb]$range_min [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]$range_min[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]$range_min[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#0000bb]$page_max[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]$range_max[/COLOR][COLOR=#007700]; 
             
            [/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000bb]$page_min [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700])?[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700]; 
            [/COLOR][COLOR=#0000bb]$page_max[/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000bb]$page_max [/COLOR][COLOR=#007700]< ([/COLOR][COLOR=#0000bb]$page_min [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]))?[/COLOR][COLOR=#0000bb]$page_min [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]$page_max[/COLOR][COLOR=#007700]; 
            if([/COLOR][COLOR=#0000bb]$page_max [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#0000bb]$numofpages[/COLOR][COLOR=#007700]){ 
                [/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000bb]$page_min [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700])?[/COLOR][COLOR=#0000bb]$numofpages [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]; 
                [/COLOR][COLOR=#0000bb]$page_max[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]$numofpages[/COLOR][COLOR=#007700]; 
            } 
             
            [/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000bb]$page_min [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700])?[/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]:[/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700]; 
             
            if( !empty([/COLOR][COLOR=#0000bb]$extra[/COLOR][COLOR=#007700])){ 
                [/COLOR][COLOR=#0000bb]$extra_p[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]'&' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$extra[/COLOR][COLOR=#007700]; 
            } 
             
            [/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]]= [/COLOR][COLOR=#0000bb]rtrim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]],[/COLOR][COLOR=#dd0000]"/"[/COLOR][COLOR=#007700]); [/COLOR][COLOR=#ff8000]//clean the extra / if needed 
             

            [/COLOR][COLOR=#007700]if(([/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]> ([/COLOR][COLOR=#0000bb]$range [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]$range_min[/COLOR][COLOR=#007700])) && ([/COLOR][COLOR=#0000bb]$numofpages [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#0000bb]$range[/COLOR][COLOR=#007700])){ 
                [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]'<a class="num"  title="First" href="' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]'/?page=1' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$extra_p [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'"><</a> '[/COLOR][COLOR=#007700]; 
            } 
             
            if([/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]){ 
                [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]'<a class="num" href="' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]'/?page=' [/COLOR][COLOR=#007700]. ([/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) . [/COLOR][COLOR=#0000bb]$extra_p [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'">Previous</a> '[/COLOR][COLOR=#007700]; 
            } 
             
            for([/COLOR][COLOR=#0000bb]$i[/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]$page_min[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000bb]$i [/COLOR][COLOR=#007700]<= [/COLOR][COLOR=#0000bb]$page_max[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000bb]$i[/COLOR][COLOR=#007700]++){ 
                if([/COLOR][COLOR=#0000bb]$i [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]$current_page[/COLOR][COLOR=#007700]) 
                    [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]'<span class="num"><strong>' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$i [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'</strong></span> '[/COLOR][COLOR=#007700]; 
                else 
                    [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]'<a class="num" href="' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]'/?page=' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$i [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$extra_p [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'">' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$i [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'</a> '[/COLOR][COLOR=#007700]; 
            } 
             
            if([/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]< [/COLOR][COLOR=#0000bb]$numofpages[/COLOR][COLOR=#007700]){ 
                [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]' <a class="num" href="' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]'/?page=' [/COLOR][COLOR=#007700]. ([/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]+ [/COLOR][COLOR=#0000bb]1[/COLOR][COLOR=#007700]) . [/COLOR][COLOR=#0000bb]$extra_p [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'">Next</a>'[/COLOR][COLOR=#007700]; 
            } 
             
            if(([/COLOR][COLOR=#0000bb]$current_page [/COLOR][COLOR=#007700]< ([/COLOR][COLOR=#0000bb]$numofpages [/COLOR][COLOR=#007700]- [/COLOR][COLOR=#0000bb]$range_max[/COLOR][COLOR=#007700])) && ([/COLOR][COLOR=#0000bb]$numofpages [/COLOR][COLOR=#007700]> [/COLOR][COLOR=#0000bb]$range[/COLOR][COLOR=#007700])){ 
                [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]' <a class="num" title="Last" href="' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_SERVER[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'REDIRECT_URL'[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]'/?page=' [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$numofpages [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$extra_p [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#dd0000]'">></a> '[/COLOR][COLOR=#007700]; 
            } 
            return [/COLOR][COLOR=#0000bb]$page_pagination[/COLOR][COLOR=#007700]; 
        } [/COLOR][COLOR=#ff8000]//end if more than 1 page 
    [/COLOR][COLOR=#007700]}  [/COLOR][/COLOR]
-HL
 
So how to integrate that code into the original script?
 
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock