How to fix the custom wordpress project portfolio pagination

How to fix the custom wordpress project portfolio pagination ? Below is my code which is working perfect but pagination is not coming. Can I achieve it through any plugins like WP PageNavi ?

Below is my custom Template Name: Portfolio

<?php
/*
Template Name: Portifolio
*/
?>
<?php
get_header(); ?>

<div class="single-full-width-container single-page-header-container">
  <header class="container">
    <?php
the_title('<h1 class="single-page-heading">', '</h1>'); ?>
    <ul class="single-page-breadcrumbs">
      <?php

if (function_exists('bcn_display') && !is_front_page())
    {
    bcn_display();
    }

?>
    </ul>
  </header>
</div>
<div class="container">
  <div class="row">
    <main role="main" class="isotope-portfolio portfolio-wrapper four-cols-portfolio span12">
      <div class="row">
        <?php
$terms = get_terms("tagportifolio");
$count = count($terms);
echo '<ul id="isotope-filters" class="pagination-centered unstyled">';
echo '<li><a href="#all" data-filter="*">Show All</a></li>';

if ($count > 0)
    {
    foreach($terms as $term)
        {
        $termname = strtolower($term->name);
        $termname = str_replace(' ', '-', $termname);
        echo '<li><a href="#' . $termname . '" data-filter=".' . $termname . '" rel="' . $termname . '">' . $term->name . '</a></li>';
        }
    }

echo "</ul>";
?>
        <div id="container">
          <?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$loop = new WP_Query(array(
    'post_type' => 'project',
    'posts_per_page' => 5,
    'paged' => $paged
));
$count = 0;
?>
          <?php

if ($loop):
    while ($loop->have_posts()):
        $loop->the_post(); ?>
          <?php
        $terms = get_the_terms($post->ID, 'tagportifolio');
        if ($terms && !is_wp_error($terms)):
            $links = array();
            foreach($terms as $term)
                {
                $links[] = $term->name;
                }

            $links = str_replace(' ', '-', $links);
            $tax = join(" ", $links);
        else:
            $tax = '';
        endif;
?>
          <article class="portfolio-article item <?php
        echo strtolower($tax); ?> span4">
            <?php
        $infos = get_post_custom_values('_url'); ?>
            <div class="portfolio-content article-content">
              <?php
        if (has_post_thumbnail())
            {
            $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id() , 'large');
            echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" rel="lightbox" class="portfolio-teaser-pic fancybox">';
            the_post_thumbnail(array(
                370,
                370
            ));
            echo '</a>';
            }

?>
              <div class="meta-info"> <span class="meta-info-buttons likes-no">
                <?php
        echo $term->name; ?>
                </span> <span class="meta-info-buttons comments-no"><a href="<?php
        echo $infos[0]; ?>">Live Preview</a></span> <span class="meta-info-buttons more-details"><a href="<?php
        the_permalink() ?>">More Details</a></span></div>
              <div class="portfolio-content-wrap">
                <h1 class="portfolio-heading article-heading"> <a href="<?php
        the_permalink() ?>">
                  <?php
        the_title(); ?>
                  </a> </h1>
                <p>
                  <?php
        echo get_the_excerpt(); ?>
                </p>
              </div>
            </div>
          </article>
          <?php
    endwhile;
else: ?>
          <p>Sorry, no portfolio entries for while.</p>
          <?php
endif; ?>
          <?php
wp_reset_query(); ?>
        </div>
        <?php

if (function_exists('wp_pagenavi'))
    {
    wp_pagenavi();
    wp_reset_postdata(); // avoid errors further down the page
    }

?>
      </div>
    </main>
  </div>
</div>
<?php
get_footer(); ?>

Related posts

Leave a Reply

1 comment

  1. You need to use following

      echo paginate_links( array(
                        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $loop->max_num_pages,
                        'next_text'    => __('Next »'),
                    ) );
    

    Here is an example of how this is implemented in WordPress.