我面临一个奇怪的问题。分页仅对一个类别给出404错误。其他人工作正常。我使用了最新版本的WP和Genesis主题。我试图改变那个特定类别的鼻涕虫,但运气不好。我的代码是
<?php
function be_custom_loop()
{
$category = get_category(get_query_var(\'cat\'));
$cat_id = $category->cat_ID;
$cat_name = $category->name;
echo \'<div class="home_title">\' . $cat_name . \'</div>\';
global $wp_query;
$paged = (get_query_var(\'paged\')) ? absint(get_query_var(\'paged\')) : 1;
$wp_query = new WP_Query
(
array
(
\'posts_per_page\' => 8,
\'cat\' => $cat_id,
\'paged\' => $paged
)
);
if (have_posts()) :
while (have_posts()) : the_post();
$post_thumb = str_replace(home_url(), "", get_post_thumb($post->ID));
echo \'<div class="cat-post"><div class="cat-post-img"><a href="\' . get_the_permalink() . \'"><img src="\' . get_stylesheet_directory_uri() . \'/img.php?w=300&h=200&a=t&src=\' . $post_thumb . \'" /></a></div><div class="cat-post-title"><a href="\' . get_the_permalink() . \'">\' . get_the_title() . \'</a></div></div>\';
endwhile;
do_action(\'genesis_after_endwhile\');
endif;
wp_reset_query();
}
add_action(\'genesis_loop\', \'be_custom_loop\');
remove_action(\'genesis_loop\', \'genesis_do_loop\');
genesis();
我需要你的指导来解决这个问题。
谢谢
最合适的回答,由SO网友:IFightCode 整理而成
一团糟,但这解决了我的问题
<?php
function be_custom_loop()
{
$category = get_category(get_query_var(\'cat\'));
$cat_id = $category->cat_ID;
$cat_name = $category->name;
echo \'<div class="home_title">\' . $cat_name . \'</div>\';
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'cat\' => $cat_id,
\'paged\' => $paged
);
query_posts($args);
// The Loop
while (have_posts()) : the_post();
$post_thumb = str_replace(home_url(), "", get_post_thumb($post->ID));
echo \'<div class="cat-post"><div class="cat-post-img"><a href="\' . get_the_permalink() . \'"><img src="\' . get_stylesheet_directory_uri() . \'/img.php?w=300&h=200&a=t&src=\' . $post_thumb . \'" /></a></div><div class="cat-post-title"><a href="\' . get_the_permalink() . \'">\' . get_the_title() . \'</a></div></div>\';
endwhile;
//wp_pagenavi();
do_action(\'genesis_after_endwhile\');
// Reset Query
wp_reset_query();
}
add_action(\'genesis_loop\', \'be_custom_loop\');
remove_action(\'genesis_loop\', \'genesis_do_loop\');
genesis();