我正在使用wordpress分页。我有代码问题。分页在主页上正常工作。但在标签页和类别页面上显示404错误。当我去第一次显示的任何标签或类别时,但是当我导航到下一页时显示404页面错误。
这是分页代码。
<?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)."'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</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)."'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div>\n";
}
}
?>
这里是循环
<?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();
?>
任何人都可以帮我解决那里的错误吗?
答案 0 :(得分:0)
我敢打赌你应该在档案页面上使用paginate_links() function而不是get_pagenum_link()......
答案 1 :(得分:0)
1)在WordPress中以管理员身份登录。
2)转到“设置”选项卡。
3)转到阅读标签。 4)将博客页面最多显示从默认值10更改为任何数字*小于10.例如,5。
5)保存更改。
查看博客。
将数字编辑为小于10,希望它能帮到你。它固定了我的。
调试时我发现每页默认帖子选项应该小于query_posts函数中的任何自定义posts_per_page。这就是全部。很奇怪,但这是事实。