Creating WordPress Pagination Without Plugins
WordPressCreating pagination without a plugin in involves a few steps. We'll go through these steps in order.
CSS Codes
style.css the following to the file CSS We add the codes. You can customize it as you like.
/* Paging */ .wp_paging { margin: 0 0 20px; padding: 0; } .wp_paging ul { margin: 0; padding: 0; list-style: none; } .wp_paging ul li { margin: 0; padding: 0; display: inline; } .wp_paging ul li a { float: left; display:block; color: #666; text-decoration: none; margin-right: 5px; padding: 5px 10px; background-color: #FFFFFF; border: 1px solid #999; } .wp_paging ul li a:hover { color: #090; } /* Paging End */
Creating a Function
functions.php We add the following function to the file. Inside the function html You can customize the codes.
/* pagination head */ function pagination($pages = '', $range = 2) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == '') { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo "<div class='wp_paging'><ul>"; if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='/en/".get_pagenum_link(1)."/'>First</a></li>"; if($paged > 1 && $showitems < $pages) echo "<li><a href='/en/".get_pagenum_link($paged - 1)."/'>Back</a></li>"; for ($i=1; $i <= $pages; $i++) { if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) { echo ($paged == $i)? "<li><a href='#'>".$i."</a></li>":"<li><a href='/en/".get_pagenum_link($i)."/'>".$i."</a></li>"; } } if ($paged < $pages && $showitems < $pages) echo "<li><a href='/en/".get_pagenum_link($paged + 1)."/'>Next</a></li>"; if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='/en/".get_pagenum_link($pages)."/'>Last</a></li>"; echo "</ul><div class='cleaner'></div></div>"; } } /* end pagination */
Adding Pagination
We use the code below to add pagination wherever we want within the theme.
<?php sayfalama(); ?>