1

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.

2

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);
} ?>
|improve this answer|||||
  • Thank you for the answer.. the pagination is working but my client changed his mind, he wants a scroll... take a look at the bottom of the content dev.freelanceu.net/mjl/fitnessadventure, it displays 5 videos but its 13 on that category, that's he wants to scroll it sideways to reveal the remaining videos. I'm not good in jquery either javascript that's why I don't know how to deal with it. Thanks :) – markyeoj Jan 20 '12 at 1:08
  • @markyeoj - If your client wants it to now scroll then I recommend you start up a different question outlining what you are after and what you have tried so far. jQuery and JavaScript questions would be better asked on Stack Overflow. – Brady Feb 21 '12 at 14:40
  • Actually this doesn't work for me, throwing this error: "Notice: Undefined variable: loop " – MrKainig Mar 20 '16 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.