How to Create WordPress Pagination (page navigation) – No Plugin

Today fusionpeach.com is keep growing up. I’ve already released 22 articles and now you can see only 10 latest posts. Therefore we need to add a new wordpress plugin or create it by ourself to help us access the old page. That’s sure, fusionpeach is my classroom. For knowledge I’ll try to do everything by my self. Let’s start!

1. Browse to you theme folder and open file “function.php” then paste the following code.

<?php
function fusion_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='pagination'><span class='textpage'>".PAGE."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='.get_pagenum_link($paged – 1).'>&lsaquo;</a>";

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

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

if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
?>

2. After we already have a function, we need to call it by open file “index.php” then write the function call below. (I placed it before the line for get wordpress sidebar tag)

<?php fusion_pagination($additional_loop-&gt;max_num_pages); ?>

3. Now we can access to the older ten post but we still need to decor it a bit by putting following CSS.

/* --------Pagination------------*/
.pagination {
clear: both;
padding: 0 20px;
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: #555;
}

.pagination a:hover{
color: #fff;
background: #3279BB;
}

.pagination span.textpage {
background: none;
color: #000;
}

.pagination .current{
padding: 6px 9px 5px 9px;
background: #3279BB;
color: #fff;
}

4. Repeat place the code that show in No.2 into “search.php” and “archive.php”. Here is the result.

How to Display Recent Comment with Gravatar – No Plugin

WordPress has already provided you the Recent Comment by widget setting but it has no picture gravatar. Today I’m working on it, this tutorial will show you all what I’ve done.

config the avatar type
1. Browse to you theme folder. Open “Sidebar.php” then put this code.

<div>
<h2>Recent Comments</h2>
<ul>
  <ul><!--?php <br ?--> $comments = get_comments('number=5');</ul>
</ul>
<ul>
  <ul>foreach($comments as $comm) :$url = '</ul>
</ul>

<a title="'.$comm-&gt;comment_author .' | '.get_the_title($comm-&gt;comment_post_ID).'" href="'. get_permalink($comm-&gt;comment_post_ID).'#comment-'.$comm-&gt;comment_ID .'">' . $comm-&gt;comment_author . '</a>

<ul>
  <ul>';</ul>
</ul>
<ul>
  <ul>?&gt;
     <li><!--?php echo get_avatar($comm--->comment_author_email, 30); ?&gt;</li>
  </ul>
</ul>

</div>

2. Open “style.css” then put the following selector to manage displaying style.

<div>
<h2>Recent Comments</h2>
<ul>
  <?php
  $comments = get_comments('number=5');
  foreach($comments as $comm) :$url = '<a href="'. get_permalink($comm->comment_post_ID).'#comment-'.$comm->comment_ID .'" title="'.$comm->comment_author .' | '.get_the_title($comm->comment_post_ID).'">' . $comm->comment_author . '</a>';
  ?>

  <li>
     <?php echo get_avatar($comm->comment_author_email, 30); ?>
     <strong><?php echo $url; ?></strong>
     <p><?php echo $comm->comment_content; ?></p>
  </li>

  <?php  endforeach;  ?>
</ul>
</div>

3. Upload “sidebar.php” and “style.css” to your hosting. Go through Admin page > Settings > Discussion then select your prefer type of Avatar. Finished, here is what I’ve got.
Display recent comment with Gravatar