简体   繁体   中英

Wordpress Pagination 404 error for tags and categories

I am working with wordpress pagination. i have problem with code. pagination is working fine on main page. but showing 404 error on tag page and category page. when i go to any tag or category its showing first time ok but when i navigate to next page its showing 404 page error.

here is pagination code.

    <?php
function kriesi_pagination($pages = '', $range = 2)
{  
     $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'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</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)."'>&rsaquo;</a>";  
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
         echo "</div>\n";
     }
}
?>

here is loop

<?php global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'fahrzeug' ) );
query_posts( $args );
if ( have_posts() ) : while ( have_posts() ) : the_post(); 
$omc_review_enable =  get_post_meta(get_the_ID(), 'omc_review_enable', true);
$omc_final_score =  get_post_meta(get_the_ID(), 'omc_final_score', true);
$omc_final_percentage = $omc_final_score * 20 ;
$format = get_post_format();
if ( false === $format )
$format = 'standard';
?>      

<article class="omc-blog-two omc-half-width-category" id="post-<?php the_ID(); ?>">     
    <?php 
      global $h_sticky;
      global $displayed;
      $home_page = get_option ('shareit_home', 0);
      if (!$displayed and $h_sticky && $home_page == 1) {
        echo $h_sticky;
        $displayed = true;
      } 
    ?>  
    <div class="omc-resize-290 omc-blog">       

        <?php $category = get_the_category();?>
        <h3 class="omc-blog-two-cat"><a href="<?php echo home_url(); echo ('/?cat='.$category[0]->term_id); ?>"><?php echo $category[0]->cat_name; ?></a></h3>

        <?php if ($omc_review_enable == 1) { ?><span class="omc-blog-two-stars-under leading-article"><span class="omc-blog-two-stars-over leading-article" style="width:<?php echo $omc_final_percentage; ?>%"></span></span><?php } ?>

        <a href="<?php the_permalink();?>" >

            <?php if ($format == 'video' || $format == 'audio') { ?><span class="module-a-video-icon-big omc-half-width-icon omc-module-b-left"></span><?php } ?>

            <?php if (has_post_thumbnail()) { 
                //Changes made by wisdmlabs starts
                //the_post_thumbnail('half-landscape', array('class' => 'omc-image-resize')); //this is the original line
                the_post_thumbnail('mycustomsize',array('class'=>'custom-img-size'));
                //changes made by wisdmlabs ends

            } else {

                //echo('<img src="'.get_template_directory_uri().'/images/no-image-half-landscape.png" class="omc-image-resize" alt="no image" />');

            } ?>

        </a>

    </div><!-- /omc-resize-290 -->

    <div class="omc-blog-two-text">

        <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>

<!--

        <p class="omc-blog-two-date">
        <?php
         the_time('F jS, Y') ?> | <em><?php
             _e('by', 'gonzo'); ?> <?php the_author() ?></em></p>

-->

        <p class="omc-blog-two-exceprt" ><?php wpe_excerpt('blog_2', 'wpe_excerptmore'); ?></p>

<a href="<?php echo do_shortcode('[wpv-post-field name="Webseite zum Fahrzeug"]'); ?>" target="_blank" ><!--<?php echo do_shortcode('[wpv-post-field name="Webseite zum Fahrzeug"]'); ?>--><button class="btn_map" style="background-color:red;

" ><span class="button_title">Zum Anbieter</span></button></a>



        <br class="clear" />

    </div><!-- /omc-blog-two-text -->

</article>
<?php
//
//kriesi_pagination(2,2);
//
endwhile;  endif; ?> 
<br class="clear" />
<?php
kriesi_pagination();
wp_reset_query();
?>

can any one help me what is wrong there????

我敢打赌,您应该在存档页面上使用paginate_links()函数而不是get_pagenum_link()...

1) Login as the admin in WordPress.

2)Go to the Settings tab.

3)Go to the Reading tab. 4)Change the Blog pages show at most from the default 10 to any number *less than 10. For example, 5.

5)Save the changes.

View the blog.

edit the number to less than 10, hope it helps you out. It fixed mine.

while debugging i found out that default posts per page option should be less than any custom posts_per_page in query_posts function. That's all. Weird, but that's the fact.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM