Custom Pagination in wp

Add custom pagination in wordpress

pagination

paste this function in function.php

function pagination($pages = '', $range = 4)
{
     $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="pagination"><span>Page ".$paged." of ".$pages."</span>";
         if($paged &gt; 2 &amp;&amp; $paged &gt; $range+1 &amp;&amp; $showitems &lt; $pages) echo &quot;<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
         if($paged &gt; 1 &amp;&amp; $showitems &lt; $pages) echo &quot;<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

         for ($i=1; $i = $paged+$range+1 || $i &lt;= $paged-$range-1) || $pages &lt;= $showitems ))
             {
                 echo ($paged == $i)? &quot;<span class="current">".$i."</span>":"<a href='".get_pagenum_link($i)."' class="inactive">".$i."</a>";
             }
         }

         if ($paged &lt; $pages &amp;&amp; $showitems &lt; $pages) echo &quot;<a>Next &rsaquo;</a>";
         if ($paged &lt; $pages-1 &amp;&amp;  $paged+$range-1 &lt; $pages &amp;&amp; $showitems &lt; $pages) echo &quot;<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
         echo "</div>
\n";
     }
}

After that just add this to view pagination next prev button and numbers…

<div class="customPaginav">
<div class="prev"></div>
max_num_pages);} ?&gt;
<div class="next"></div>
</div>

adding in custom post type or any other loop


$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

$wp_query = new WP_Query();
$wp_query->query(array(
	'post_type'=>'gallery',   // Post type name here
	'paged' => $paged,   // for adding pages according to the post
	'posts_per_page' => 5   // visible post on every page
));

Some CSS styling required

.customPaginav { overflow: hidden; clear: both; margin:30px 0; }
.customPaginav a { vertical-align: top; display: inline-block; font-size: 12px; border-right: 2px solid #ffffff; padding: 4px 9px; text-decoration: none; width: auto; color: #fff; background: #555; }
.customPaginav .prev, .customPaginav .next  { float: left; }
.customPaginav .prev a, .customPaginav .next a { line-height: 17px; }
.pagination { float: left; position: relative; font-size: 11px; line-height: 14px; margin: 0; }
.pagination span { display: block; float: left; margin: 0 3px 0 0; padding: 6px 9px 5px 9px; text-decoration: none; width: auto; color: #fff; background: #555; }
.pagination a { display: block; float: left; margin: 0 1px 0 0; padding: 6px 9px 5px 9px; text-decoration: none; width: auto; color: #fff; background: #555; }
.pagination a:hover { color: #fff; background: #941e22;}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s