CyberX

mobile

Simple pagination PHP script with semantic HTML 5

This is a simple PHP pagination script for your sites writed by CyberX labs. Code below represents how to works pagination:

<?php

/**
 *	Pagination template
 */

$render_node .= '<nav class="revolver__pagination">';
$render_node .= '<ul role="navigation" itemscope itemtype="http://schema.org/SiteNavigationElement">';


/* limit pages per section */
$limit = 5;

for( $i = 1; $i <= $pages_count; $i++) {


	$link = $i === 1 ? '/' : '/?page='. $i; 


	if( $i >= 1 ) {

		$prev = (int)pager['current'] <= 1 ? '/' : '/?page='. ((int)pager['current'] - 1);

		$render_node_prev = (int)pager['current'] <= 1 ? '' : '<li><a itemprop="url" href="'. $prev .'"><span itemprop="name">&laquo;</span></a></li>';

	}

	if( $i <= ((int)$pages_count - 1) ) {

		$next = pager['current'] >= $pages_count ? '/' : '/?page='. ((int)pager['current'] + 1);

		$render_node_next = pager['current'] >= $pages_count ? '' : '<li><a itemprop="url" href="'. $next .'"><span itemprop="name">&raquo;</span></a></li>';


	}



	if( pager['current'] === $i ) {
	
		$render_node_links .= '<li><span><i>'. $i .'</i></span></li>';
	
	} 
	else {

		if( $i <= $pages_count - 1  ) {

			if( $i <= $limit ) {

				$render_node_links .= pager['current'] === 0 && $i === 1 ? '<li><span><i>'. $i .'</i></span></li>' : '<li><a itemprop="url" href="'. $link .'"><span itemprop="name">'. $i .'</span></a></li>';

				
			}

			if( $i == $pages_count - 1 ) {

				$render_node_links .= '<li><span><i>...</i></span></li>';
			
			}
		
		} 
		else if( $i == $pages_count ) {

			$render_node_links .= pager['current'] === 0 && $i === 1 ? '<li><span><i>'. $i .'</i></span></li>' : '<li><a itemprop="url" href="'. $link .'"><span itemprop="name">'. $i .'</span></a></li>';
		
		}

	}

} 


$render_node .= $render_node_prev . $render_node_links . $render_node_next;
$render_node .= '</ul>';
$render_node .= '</nav>';

?>

Few vars you need to modify: $limit - how many pages show in pages section; $pages_count - total pages and pager['current'] - current page.

RevolveR pagination includes semantic microdata HTML 5 for more flexible crawling your website pages. Script works on any PHP version that supports define variables.

Reviews

You can write here as guest with moderation. Please confirm your person if you have an account or register.

Add a review as guest
Lets draw: