Wordpress: customowa ladna paginacja (nawigacja)
<?php if(function_exists('pagenavi')) { pagenavi(); } ?>
/* Function that performs a Boxed Style Numbered Pagination (also called Page Navigation).
Function is largely based on Version 2.4 of the WP-PageNavi plugin */
function pagenavi($before = '', $after = '') {
global $wpdb, $wp_query;
$pagenavi_options = array();
// $pagenavi_options['pages_text'] = ('Page %CURRENT_PAGE% of %TOTAL_PAGES%:');
$pagenavi_options['pages_text'] = '';
$pagenavi_options['current_text'] = '%PAGE_NUMBER%';
$pagenavi_options['page_text'] = '%PAGE_NUMBER%';
$pagenavi_options['first_text'] = ('');
$pagenavi_options['last_text'] = ('');
$pagenavi_options['next_text'] = '>';
$pagenavi_options['prev_text'] = '<';
$pagenavi_options['dotright_text'] = '...';
$pagenavi_options['dotleft_text'] = '...';
$pagenavi_options['num_pages'] = 5; //continuous block of page numbers
$pagenavi_options['always_show'] = 0;
$pagenavi_options['num_larger_page_numbers'] = 0;
$pagenavi_options['larger_page_numbers_multiple'] = 5;
//If NOT a single Post is being displayed
/*http://codex.wordpress.org/Function_Reference/is_single)*/
if (!is_single()) {
$request = $wp_query->request;
//intval — Get the integer value of a variable
/*http://php.net/manual/en/function.intval.php*/
$posts_per_page = intval(get_query_var('posts_per_page'));
//Retrieve variable in the WP_Query class.
/*http://codex.wordpress.org/Function_Reference/get_query_var*/
$paged = intval(get_query_var('paged'));
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
//empty — Determine whether a variable is empty
/*http://php.net/manual/en/function.empty.php*/
if(empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = intval($pagenavi_options['num_pages']);
$larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
$larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor($pages_to_show_minus_1/2);
//ceil — Round fractions up (http://us2.php.net/manual/en/function.ceil.php)
$half_page_end = ceil($pages_to_show_minus_1/2);
$start_page = $paged - $half_page_start;
if($start_page <= 0) {
$start_page = 1;
}
$end_page = $paged + $half_page_end;
if(($end_page - $start_page) != $pages_to_show_minus_1) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if($end_page > $max_page) {
$start_page = $max_page - $pages_to_show_minus_1;
$end_page = $max_page;
}
if($start_page <= 0) {
$start_page = 1;
}
$larger_per_page = $larger_page_to_show*$larger_page_multiple;
//round_num() custom function - Rounds To The Nearest Value.
$larger_start_page_start = (round_num($start_page, 10) + $larger_page_multiple) - $larger_per_page;
$larger_start_page_end = round_num($start_page, 10) + $larger_page_multiple;
$larger_end_page_start = round_num($end_page, 10) + $larger_page_multiple;
$larger_end_page_end = round_num($end_page, 10) + ($larger_per_page);
if($larger_start_page_end - $larger_page_multiple == $start_page) {
$larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
$larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
}
if($larger_start_page_start <= 0) {
$larger_start_page_start = $larger_page_multiple;
}
if($larger_start_page_end > $max_page) {
$larger_start_page_end = $max_page;
}
if($larger_end_page_end > $max_page) {
$larger_end_page_end = $max_page;
}
if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) {
/*http://php.net/manual/en/function.str-replace.php */
/*number_format_i18n(): Converts integer number to format based on locale (wp-includes/functions.php*/
$pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
$pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
echo $before.'<div class="pagination-wrapper"><div class="pagination-outer">'."\n";
if(!empty($pages_text)) {
echo '<span class="pages">'.$pages_text.'</span>';
}
//Displays a link to the previous post which exists in chronological order from the current post.
/*http://codex.wordpress.org/Function_Reference/previous_post_link*/
// previous_posts_link($pagenavi_options['prev_text']);
echo (($paged-1) >= 1)?'<a class="arr-left"':'<div class="arr-left"';
echo (($paged-1) >= 1)?'href="'.get_pagenum_link($paged - 1).'"':'';
echo 'title="wstecz">'.__('Poprzednie').'</';
echo (($paged-1) >= 1)?'a>':'div>';
echo "<div class='pagination'>";
echo "<div class='pag-int'>";
if ($start_page >= 2 && $pages_to_show < $max_page) {
$first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
//esc_url(): Encodes < > & " ' (less than, greater than, ampersand, double quote, single quote).
/*http://codex.wordpress.org/Data_Validation*/
//get_pagenum_link():(wp-includes/link-template.php)-Retrieve get links for page numbers.
echo '<a href="'.esc_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">1</a>';
if(!empty($pagenavi_options['dotleft_text'])) {
echo '<span class="expand">'.$pagenavi_options['dotleft_text'].'</span>';
}
}
if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="single_page" title="'.$page_text.'">'.$page_text.'</a>';
}
}
for($i = $start_page; $i <= $end_page; $i++) {
if($i == $paged) {
$current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
echo '<span class="current">'.$current_page_text.'</span>';
} else {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="single_page" title="'.$page_text.'">'.$page_text.'</a>';
}
}
if ($end_page < $max_page) {
if(!empty($pagenavi_options['dotright_text'])) {
echo '<span class="expand">'.$pagenavi_options['dotright_text'].'</span>';
}
$last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
echo '<a href="'.esc_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$max_page.'</a>';
}
// next_posts_link($pagenavi_options['next_text'], $max_page);
echo '</div>';
echo '</div>';
echo (($paged+1) <= $wp_query->max_num_pages)?'<a class="arr-right"':'<div class="arr-right"';
echo (($paged+1) <= $wp_query->max_num_pages)?'href="'.get_pagenum_link($paged + 1).'"':'';
echo 'title="dalej">'.__('Następne').'</';
echo (($paged+1) <= $wp_query->max_num_pages)?'a>':'div>';
if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
$page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
echo '<a href="'.esc_url(get_pagenum_link($i)).'" class="single_page" title="'.$page_text.'">'.$page_text.'</a>';
}
}
echo '</div></div>'.$after."\n";
}
}
}
/*paginacja*/
.pagination-wrapper {
width: 100%;
display: table;
border-collapse: collapse;
border: 0 none transparent;
}
.pagination-outer {
display: table-row;
}
.pagination-outer .pagination {
display: table-cell;
text-align: center;
vertical-align: bottom;
}
.pagination-outer .pagination .pag-int {
display: block;
margin: 0 auto;
height: 19px;
position: relative;
top: -6px;
}
.pagination-outer .pagination .pag-int span.expand,
.pagination-outer .pagination .pag-int span.current,
.pagination-outer .pagination .pag-int a {
margin-right: 0.15em;
margin-left: 0.15em;
background: #F7F6F6; /* Old browsers */
background: -moz-linear-gradient(top, rgba(247, 246, 246, 1) 0%, rgba(239, 238, 238, 1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(247, 246, 246, 1)), color-stop(100%, rgba(239, 238, 238, 1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(247, 246, 246, 1) 0%, rgba(239, 238, 238, 1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(247, 246, 246, 1) 0%, rgba(239, 238, 238, 1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(247, 246, 246, 1) 0%, rgba(239, 238, 238, 1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(247, 246, 246, 1) 0%, rgba(239, 238, 238, 1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#f7f6f6', endColorstr = '#efeeee', GradientType = 0); /* IE6-9 */
-moz-box-shadow: 0.5px 0.866px 1px 0px rgb(180, 180, 180);
-webkit-box-shadow: 0.5px 0.866px 1px 0px rgb(180, 180, 180);
box-shadow: 0.5px 0.866px 1px 0px rgb(180, 180, 180);
width: 1.38888888888888888889em;
height: 1.38888888888888888889em;
line-height: 1.38888888888888888889em;
font-size: 1.125em;
font-family: "Roboto Condensed", sans-serif;
color: #464646;
font-weight: 700;
text-transform: uppercase;
text-align: center;
padding: 0;
position: relative;
display: inline-block;
/*display: table-cell;*/
}
.pagination-outer .pagination .pag-int span.current,
.pagination-outer .pagination .pag-int a:hover {
color: #1360a8;
}
.pagination-outer .arr-right {
display: table-cell;
position: relative;
width: 1.38888888888888888889em;
height: 1.38888888888888888889em;
font-size: 1.125em;
background-position: 0 0;
background-image: url("img/pag-next.png");
text-indent: -9999px;
}
.pagination-outer .arr-left {
display: table-cell;
position: relative;
width: 1.38888888888888888889em;
height: 1.38888888888888888889em;
font-size: 1.125em;
background-position: 0 0;
background-image: url("img/pag-prev.png");
text-indent: -9999px;
}
.pagination-outer .arr-left:hover,
.pagination-outer .arr-right:hover {
background-position: 25px 0 !important;
}