1

im trying to make the pagination work in my portfolio page, whenever i click older entries it takes me to an error page but my URL is show ...page/2. i have spent days going thru forums on how to fix this. PLS HELP!!!!

my code below, (**php files)

**register_portfolio.php 

<?php 
    $portfolio = new CPT(array(
    'post_type_name' => 'portfolio',
    'singular' => __('Portfolio', 'ninetyoneproductions'),
    'plural' => __('Portfolio', 'ninetyoneproductions'),
    'slug' => 'portfolio'
),
    array(
    'supports' => array('title', 'editor', 'thumbnail', 'comments', 'post-formats'),
    'menu_icon' => 'dashicons-portfolio'
));

$portfolio->register_taxonomy(array(
    'taxonomy_name' => 'portfolio_tags',
    'singular' => __('Portfolio Tag', 'ninetyoneproductions'),
    'plural' => __('Portfolio Tags', 'ninetyoneproductions'),
    'slug' => 'portfolio-tag'
));

**template-portfolio.php

<section id="content">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 col-md-12">     

                    <div class="row">
                        <div class="portfolio-items">

                        <?php 
                            if ( get_query_var('paged') ) {
                                $paged = get_query_var('paged');
                            } elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
                                $paged = get_query_var('page');
                            } else {
                                $paged = 1;
                            }
                            $query_args = array(
                                'post_type' => 'portfolio', 
                                'posts_per_page' => get_option('posts_per_page'),
                                'paged' => $paged
                            );
                            // the query
                            $the_query = new WP_Query( $query_args ); ?>

                            <?php if ( $the_query->have_posts() ) : ?>

                            <!-- the loop -->
                            <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

                                <div class="col-sm-6 col-md-4 item">
                                    <div class="thumbnail ">
                                        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                            <?php the_post_thumbnail('single-post-thumbnail');  ?>
                                        </a>
                                        <br>
                                        <h4> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h4>
                                        <?php edit_post_link( ' Edit', '<div><i class="fa fa-pencil"></i>', '</div>' ); ?>
                                    </div>
                                    <br>
                                </div>                                  

                                <?php endwhile; ?>
                                <!-- end of the loop -->

                                <?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1  ?>
                                      <?php
                                        $orig_query = $wp_query; // fix for pagination to work
                                        $wp_query = $custom_query;
                                        ?>
                                    <nav class="prev-next-posts">
                                        <div class="prev-posts-link">
                                        <?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); // display older posts link ?>
                                        </div>
                                        <div class="next-posts-link">
                                        <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
                                        </div>
                                    </nav>
                                     <?php
                                        $wp_query = $orig_query; // fix for pagination to work
                                        ?>
                                <?php } ?>

                                <?php
                                        wp_reset_postdata(); // reset the query 
                                    else:
                                        echo '<p>'.__('Sorry, no posts matched your criteria.').'</p>';
                                    endif; ?>
                        </div>
                    </div>

            </div>
        </div>
    </div>
<section>

**single-portfolio.php

<?php
/**
 * The template for displaying all single portfolio posts
 *

 *
 * @package 91-Productions
 */

get_header(); ?> 

    <section id="inner-headline">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <ul class="breadcrumb">
                    <li><a href="/localhost/"><i class="fa fa-home"></i></a><i class="icon-angle-right"></i></li>
                    <li><a href="localhost/portfolio/">Portfolio</a></li>
                    <li class="active"><?php the_title( '<span class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></span>' ); ?></li>
                </ul>
            </div>
        </div>
    </div>
    </section>

    <section id="content">
        <div class="container">
            <div class="row">
                <div class="col-lg-12 col-md-12" id="pi">

                <?php while ( have_posts() ) : the_post(); ?>

                        <?php get_template_part( 'template-parts/content', 'portfolio' ); ?>

                         <!--the_post_navigation();-->
                </div>

                <div class="col-lg-12 col-md-12"
                        <?php 
                            // If comments are open or we have at least one comment, load up the comment template.
                            if ( comments_open() || get_comments_number() ) :
                                comments_template();
                            endif;
                        ?> 

                        <!--// End of the loop. -->
                        <?php endwhile; ?>      

                </div>

            </div>
        </div>
    </section>

<?php

get_footer();

**content-portfolio.php

<?php
/**
 * The template for displaying all portfolio contents
 *
 * @package 91-Productions
 */
?>

<?php
    $productionDesc             =   get_field('production_name');
    $AwardDesc                  =   get_field('award');
    $directorName               =   get_field('director_name');
    $AssistantCamera            =   get_field('assistant_camera');
    $location                   =   get_field('location');
    $actors__actress_model      =   get_field('actor_actress_model');             
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="entry-header">
        <?php the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
            <hr>
    </header> 
                    <?php if (has_post_thumbnail()) { ?>
                        <div class="post-image" >
                            <?php the_post_thumbnail(); ?>
                        </div>
                    <?php } ?>

                 <div class="col-lg-8 col-md-8">
                    <div class="post_body" id="ct">
                        <?php the_content(); ?>
                    </div> <br>
                    <a href="#" class="btn btn-warning">Hire Us Now</a>
                     <?php edit_post_link( ' Edit', '<div><i class="fa fa-pencil"></i>', '</div>' ); ?>
                </div>

                <div class="col-lg-4" ID="pas">
                    <aside class="right-sidebar">
                    <div class="widget">
                        <h5 class="widgetheading">PRODUCTION</h5>
                        <p><?php echo $productionDesc ?></p>
                    </div>
                    <div class="widget">
                        <h5 class="widgetheading">AWARDS</h5>
                        <p><?php echo $AwardDesc ?></p>
                    </div>
                    <div class="widget">
                        <h5 class="widgetheading">DIRECTOR</h5>
                        <p><?php echo $directorName ?></p>
                    </div>
                    <div class="widget">
                        <h5 class="widgetheading">ASSISTANT CAMERA</h5>
                        <p><?php echo $AssistantCamera ?></p>
                    </div>
                    <div class="widget">
                        <h5 class="widgetheading">LOCATION</h5>
                        <p><?php echo $location ?></p>
                    </div>
                    <div class="widget">
                        <h5 class="widgetheading">MODEL</h5>
                        <p><?php echo $actors__actress_model ?></p>
                    </div>
                    </aside>
                </div>


</article> 
  • 1
    Why do you create a new query in the template instead of using the default main query? – Milo May 26 '17 at 22:43
  • so what do you advise i should do? pls help!! – Abaz Udosen May 27 '17 at 20:20
  • whenever i click on old enteries, it takes me to an error page, but the URL structure show .../page/2 – Abaz Udosen May 27 '17 at 20:21
  • MIlo its a custom query for a portfolio page, some1 pls help with this – Abaz Udosen May 28 '17 at 15:16
  • PLEASE HELP!!!!!!!! – Abaz Udosen May 28 '17 at 17:41

Your Answer

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

Browse other questions tagged or ask your own question.