How to add pagination to my code?

I just want to ask how can I add pagination here in this code:

<?php if ( get_option('webly_display_media') == 'on' ){ ?>
                    <div id="recent-projects">
                        <div id="recent-projects-right">
                            <div id="recent-projects-content" class="clearfix">
                                <?php 
                                    $args=array(
                                        'showposts' => '7',
                                        'category__not_in' => get_option('webly_exlcats_media')
                                    );
                                    query_posts($args);
                                ?>
                                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                                    <?php 
                                        $width = 140;
                                        $height = 72;
                                        $titletext = get_the_title();
                                        $thumbnail = get_thumbnail($width,$height,'project-image',$titletext,$titletext,true,'Media');
                                        $thumb = $thumbnail["thumb"];
                                        $et_medialink = get_post_meta($post->ID,'et_medialink',true) ? get_post_meta($post->ID,'et_medialink',true) : '';
                                        $et_videolink = get_post_meta($post->ID,'et_videolink',true) ? get_post_meta($post->ID,'et_videolink',true) : '';
                                    ?>
                                    <div class="project">
                                        <?php if ( $et_medialink <> '' ) { ?>
                                            <a href="<?php echo $et_medialink; ?>">
                                        <?php } elseif ( $et_videolink <> '' ) { ?>
                                            <a href="<?php echo $et_videolink; ?>" rel="prettyPhoto[media]" class="et-video" title="<?php echo $titletext; ?>">
                                        <?php } else { ?>
                                            <a href="<?php echo $thumbnail["fullpath"]; ?>" rel="prettyPhoto[media]" title="<?php echo $titletext; ?>">
                                        <?php } ?>
                                                <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, 'project-image'); ?>
                                                <span class="zoom-icon"></span>
                                                <span class="project-overlay"></span>
                                            </a>
                                    </div>  <!-- end .project -->
                                <?php endwhile; ?>
                                <?php endif; wp_reset_query(); ?>

                            </div> <!-- end #recent-projects-content -->
                        </div> <!-- end #recent-projects-right -->
                    </div> <!-- end #recent-projects -->

My posts has a featured video and currently that code displays 5 featured video base on the category. The problem is, I already have 11 posts in that category but the theme can only display 5 posts so I want to have a pagination for that. Can you help me? Here’s the development site http://dev.freelanceu.net/mjl/fitnessadventure/. You can see the above code at the bottom of the content, before the footer.

Related posts

Leave a Reply

1 comment

  1. Add this to functions.php:

    // Pagination
    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 > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</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)."">Next &rsaquo;</a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
             echo "</div>n";
         }
    }
    

    Then grab your paginated links using this:

    <?php if (function_exists("pagination")) {
        pagination($loop->max_num_pages);
    } ?>