Printing Press Wordpress

I'm trying to get pagination with a plugin wp pagenaviand a custom post type (portfolio) in WordPress, and I'm out of luck.

Here is a stripped-down version of my portfolio:

<?php get_header(); ?>

<?php
  $type = 'portfolio';
  $args=array(
    'post_type' => $type,
    'post_status' => 'publish',
    'paged' => $paged,
    'posts_per_page' => 1,
    'caller_get_posts'=> 1
  );
  $temp = $wp_query;  // assign original query to temp variable for later use   
  $wp_query = null;
  $wp_query = new WP_Query($args); 
?>

<?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
...
<?php endwhile; else : ?>
...
<?php endif; ?>

<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    $wp_query = null; $wp_query = $temp; ?>

<?php get_footer(); ?>

I have a permalink:

/%postname%/

and I saved them.

When I got to the second page of my portfolio, I get 404 pages. Any idea why this is happening?

Thanks for the help.

+5
source share
5 answers

I think you have a bad old WordPress URL Repeater.

Try adding this filter to stop it:

add_filter('redirect_canonical','my_disable_redirect_canonical');

function my_disable_redirect_canonical( $redirect_url ) {
    if ( is_single( 'portfolio' ) )
    $redirect_url = false;
    return $redirect_url;
}
+2
source

Wordpress, , WP_Query → MF_Query

MF_Query WP_Query, $your_query->next("Next Page") $your_query->prev("Previous Page") ( , .

, , , WP_Query.

, !!

0

, CPT , , , , WP_QUERY. .

, WP_QUERY

 $paged = 1;  
 if ( get_query_var('paged') ) $paged = get_query_var('paged');  
 if ( get_query_var('page') ) $paged = get_query_var('page');

$temp = $wp_query; 
                $wp_query = null; 
                $wp_query = new WP_Query(); 
                $wp_query->query('post_type=portafolio&showposts=7&orderby=post_date&order=DESC&paged='.$paged); 
 while ($wp_query->have_posts()) : $wp_query->the_post(); 

 //post format
get_template_part("content");?>

  <?php endwhile; ?>

  //pagination links here

  <?php 
      $wp_query = null; 
      $wp_query = $temp;  // Reset
   ?>

functions.php, , .

 function paginate() {  
   global $wp_query, $wp_rewrite;  
   $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;  

   $pagination = array(  
    'base' => @add_query_arg('page','%#%'),  
    'format' => '',  
    'total' => $wp_query->max_num_pages,  
    'current' => $current,  
    'show_all' => true,  
    'type' => 'plain'  
    );  

  if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );  
if ( !empty($wp_query->query_vars['s']) ) $pagination['add_args'] = array( 's' =>   get_query_var( 's' ) );  
echo paginate_links( $pagination );  
}  

 function portafolio_posts_per_page( $query ) {  
    if ( $query->query_vars['post_type'] == 'portafolio' ) $query->query_vars['posts_per_page'] = 10;  
return $query;  
}  
 if ( !is_admin() ) add_filter( 'pre_get_posts', 'portafolio_posts_per_page' );     

, , , , .

http://wp.tutsplus.com/tutorials/custom-post-type-pagination-chaining-method/

0
<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
    'post_type' => 'portfolio',
    'paged' => $paged,
    'caller_get_posts' => 1,
    'posts_per_page' => T_Panel('portfolio_page_num')
));
if (have_posts()) :
    while (have_posts()) : the_post();
        // your content loop her
    endwhile;
    wp_reset_query();
endif;

?>
0

All Articles