Promote your Service and Product online Contact us

+91 87 44 999667; +91 99 11 883996 info@3pixls.com, sales@3pixls.com

WordPress pagination


pagination
1.First Step add this code in “function.php”

[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="\&quot;pagination\&quot;">Page ".$paged." of ".$pages."";
if($paged &gt; 2 &amp;&amp; $paged &gt; $range+1 &amp;&amp; $showitems &lt; $pages) echo "<a href="&quot;.get_pagenum_link(1).&quot;">« First</a>";
if($paged &gt; 1 &amp;&amp; $showitems &lt; $pages) echo "<a href="&quot;.get_pagenum_link($paged – 1).&quot;">‹ Previous</a>";</div>
for ($i=1; $i &lt;= $pages; $i++) { if (1 != $pages &amp;&amp;( !($i &gt;= $paged+$range+1 || $i &lt;= $paged-$range-1) || $pages &lt;= $showitems ))
{
echo ($paged == $i)? "<span class="\&quot;current\&quot;">".$i."</span>":"<a class="\&quot;inactive\&quot;" href="&quot;.get_pagenum_link($i).&quot;">".$i."</a>";
}
}

if ($paged &lt; $pages &amp;&amp; $showitems &lt; $pages) echo "<a href="\&quot;&quot;.get_pagenum_link($paged">Next ›</a>";
if ($paged &lt; $pages-1 &amp;&amp; $paged+$range-1 &lt; $pages &amp;&amp; $showitems &lt; $pages) echo "<a href="&quot;.get_pagenum_link($pages).&quot;">Last »</a>";
echo "

\n";
}
}
[/php]

2. Second step add this code where you need pagination

[php]
&lt;!– then the pagination links –&gt;
&lt;?php if (function_exists("pagination")) {
pagination($additional_loop-&gt;max_num_pages);
} ?&gt;

&nbsp;

<strong>3. Third and last css</strong>

/* pagination */
.paginationmain{ display:block;
text-align: center;
}

.pagination {
clear:both;
padding:20px 0;
position:relative;
font-size:11px;
line-height:13px;
}

.pagination span, .pagination a {
display:block;
float:left;
margin: 2px 2px 2px 0;
padding:6px 9px 5px 9px;
text-decoration:none;
width:auto;
color:#fff;
background: #0486d2;
}

.pagination a:hover{
color:#000;
background: #7bc24d;
}

.pagination .current{
padding:6px 9px 5px 9px;
background: #7bc24d;
color:#000;
}
[/php]