WordPress 中文Tag标签404 tag标签分页404处理

1 篇文章 0 订阅
1 篇文章 0 订阅

1、关于中文Tag标签404问题,网上已有不少解决方案,可直接查阅解决,以下为链接之一:

http://blog.csdn.net/waitig1992/article/details/39268707


2、关于tag标签页做分页处理,点击页码有时会报404,解决方法如下:

/wp-includes/class-wp.php 的 handle_404()方法

// We will 404 for paged queries, as no posts were found.
if ( ! is_paged() ) {
   // Don't 404 for authors without posts as long as they matched an author on this site.
   $author = get_query_var( 'author' );
   if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
      status_header( 200 );
      return;
   }

   // Don't 404 for these queries if they matched an object.
   if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
      status_header( 200 );
      return;
   }

   // Don't 404 for these queries either.
   if ( is_home() || is_search() || is_feed() ) {
      status_header( 200 );
      return;
   }
}

原因是,页面加载时$wp_query->posts 查询结果为空数组,WP分页后默认会按404处理,修改代码如下:

// We will 404 for paged queries, as no posts were found.
if ( ! is_paged() ) {
   // Don't 404 for authors without posts as long as they matched an author on this site.
   $author = get_query_var( 'author' );
   if ( is_author() && is_numeric( $author ) && $author > 0 && is_user_member_of_blog( $author ) ) {
      status_header( 200 );
      return;
   }

   // Don't 404 for these queries if they matched an object.
   if ( ( is_tag() || is_category() || is_tax() || is_post_type_archive() ) && get_queried_object() ) {
      status_header( 200 );
      return;
   }

   // Don't 404 for these queries either.
   if ( is_home() || is_search() || is_feed() ) {
      status_header( 200 );
      return;
   }
}
//Tag页分页不显示404 --------------begin
else
      {
          if ( is_tag() ) {
              status_header(200);
              return;
          }
      }
//Tag页分页不显示404 --------------end

问题解决,同理,文章分类、自定义分类页如需做分页时,也需要做如上修改。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值