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 = &#039;&#039;, $range = 2) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == &#039;&#039;) { global $wp_query; $pages = $wp_query-&gt;max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo &quot;<div class='wp_paging'><ul>&quot;; if($paged &gt; 2 &amp;&amp; $paged &gt; $range+1 &amp;&amp; $showitems &lt; $pages) echo &quot;<li><a href='/en/".get_pagenum_link(1)."/'>First</a></li>&quot;; if($paged &gt; 1 &amp;&amp; $showitems &lt; $pages) echo &quot;<li><a href='/en/".get_pagenum_link($paged - 1)."/'>Back</a></li>&quot;; 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='#'>&quot;.$i.&quot;</a></li>":"<li><a href='/en/".get_pagenum_link($i)."/'>&quot;.$i.&quot;</a></li>&quot;; } } if ($paged &lt; $pages &amp;&amp; $showitems &lt; $pages) echo &quot;<li><a href='/en/".get_pagenum_link($paged + 1)."/'>Next</a></li>&quot;; if ($paged &lt; $pages-1 &amp;&amp; $paged+$range-1 &lt; $pages &amp;&amp; $showitems &lt; $pages) echo &quot;<li><a href='/en/".get_pagenum_link($pages)."/'>Last</a></li>&quot;; echo &quot;</ul><div class='cleaner'></div></div>&quot;; } } /* end pagination */

Adding Pagination

We use the code below to add pagination wherever we want within the theme.

<?php sayfalama(); ?>
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments