【发布时间】:2014-03-24 03:05:23
【问题描述】:
首先是问题,然后是尝试。
问题
问题是,如果我访问第一个类别页面以外的另一个页面,我会收到 404 NOT FOUND 错误。 在类别页面上,我有一个正常的分页。第一个站点有效。 (http://mypage.com/category/properties)
点击“下一页”按钮后,我在页面 http://mypage.com/category/properties/page/2 上并收到错误 404 NOT FOUND。
但是为什么呢?
尝试
首先我尝试了这个问题Custom Post Type and Taxonomy pagination 404 error,但exclude_from_search 和下面的查询不起作用。
我也试过这个。 http://wordpress.org/support/topic/one-again-page-not-found-on-second-and-further-pages 但是 query_posts 尝试与 WP_Query 尝试具有相同的结果。
我也尝试过带有预查询的事件。但是问题是一样的-.-
示例/PHP
<?php
/* /srv/www/mypage/wp-content/themes/twentythirteen/category-1.php */
global $wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array_merge($wp_query->query, array(
'posts_per_page' => 4,
'post_type' => 'property',
'post_status' => 'publish',
'meta_key' => 'property_typ',
'meta_value' => 'Rent',
'category_name' => null
));
$wp_query = new WP_Query($args);
echo '<ul>';
while (have_posts())
{
the_post();
echo '<li><a href="' . get_permalink(get_the_id()) . '">'
. get_the_title() . '</a></li>';
}
echo '</ul>';
echo paginate_links(array(
'base' => str_replace(99999, '%#%', esc_url(get_pagenum_link(99999))),
'total' => $wp_query->max_num_pages,
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged'))
));
结果
第 1 页
第 2 页
【问题讨论】:
-
您是否访问过
/wp-admin/option-permalinks.php来刷新重写规则?只要加载该页面就足够了,如果这确实是问题! -
那什么都没做 :( 我保存并刷新了重写规则并再次收到错误 404。
-
您正在使用辅助查询,其中主要查询定义它是 404 还是 202 页面。替换线 -
$wp_query = new WP_Query($args);尝试query_posts($args);。由于您的页面模板是category-1.php- 只有当前类别 id 为 - 1 时才会加载此模板。类别properties是否使用 id - 1 ? -
是的
properties是id=1。如果我用query_posts($args)替换查询,我也会遇到同样的问题。query_posts使用变量$wp_query... ^^ 我在哪里可以找到类别的“主要”查询?例如我的category.php没有使用query_posts...
标签: php pagination wordpress wordpress-theming