我有两个父类别,分页对它们很有效-分页url显示为:
/parent-category-1/page/2/
... etc
/parent-page/parent-category-2/page/2/
... etc
但是,当我转到子类别时,分页返回404-for,例如:
/category/parent-category-1/child-category/page/2/
... etc=404
/category/parent-category-2/child-category/page/2/
... etc=404
我正在使用WP PageNavi插件进行分页我的永久链接选项中没有设置任何自定义永久链接parent-category-1
为我的标准博客帖子添加类别
parent-category-2
设置自定义帖子类型类别的父级
以下是以下博客帖子的模板parent-category-1
(标准模板-category.php
):
<div class="feed med">
<?php
$paged = (get_query_var(\'page\')) ? get_query_var(\'page\') : 1; // FOR PAGINATION
$args = array(
\'post_type\' => \'post\',
\'category__in\' => ($cat),
\'posts_per_page\' => 5,
\'page\' => $paged, // FOR PAGINATION
);
// FOR PAGINATION - hijack the $wp_query variable temporarily
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
$second_query = new WP_Query( $args );
if ( $second_query->have_posts() ):
while( $second_query->have_posts() ) : $second_query->the_post();
$titlechars = 45000; // Character Limit - rediculously large number to eliminate limit
$posttitle = get_the_title();
$modtitle = substr($posttitle, 0, $titlechars);
$contentchars = 120; // Character Limit
$postcontent = get_the_excerpt();
$modcontent = substr($postcontent, 0, $contentchars);
echo \'<article>\';
?>
<?php
if( get_field(\'image\') ):
$attachment_id = get_field(\'image\');
$size = \'customfeatins\'; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
echo \'<a href="\' . get_permalink() . \'"><img src="\' . $image[0] . \'" alt="\' . get_the_title() .\'" width="136" height="90" /></a>\';
?>
<?php else : ?>
<?php echo \'<a href="\' . get_permalink() . \'"><img src="\'. get_template_directory_uri() .\'/assets/img/content/bf-default.gif" alt="bf-default" width="136" height="90" /></a>\' ?>
<?php endif; ?>
<?php
echo \'
<div class="right-content">
<h3 class="purple"><a href="\' . get_permalink() . \'">\' . $modtitle .\'</a></h3>
<p class="date">\' . get_the_date() .\'</p>
<p>\' . $modcontent . \'… <a href="\' . get_permalink() . \'">More ›</a></p>
</div>
</article>\';
?>
<?php
/* PageNavi at Bottom */
if (function_exists(\'wp_pagenavi\')){wp_pagenavi();}
// FOR PAGINATION - reassign the $wp_query variable to what is was originally and then reset the query back to start.
$wp_query = null;
$wp_query = $temp;
endwhile;
?>
<?php
endif;
wp_reset_postdata(); // to reset the loop
?>
</div><!-- [END] feed-->
以及下自定义帖子的模板
parent-category-2
(自定义模板-
category-parent-category-2.php
):
<div class="feed med no-border" id="the-posts">
<?php
$paged = (get_query_var(\'page\')) ? get_query_var(\'page\') : 1; // FOR PAGINATION
$category = get_the_category();
$args = array(
\'post_type\' => \'custom-post-type\',
\'posts_per_page\' => 5,
\'page\' => $paged, // FOR PAGINATION
\'category__in\' => ($cat),
);
// FOR PAGINATION - hijack the $wp_query variable temporarily
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
$second_query = new WP_Query( $args );
if ( $second_query->have_posts() ):
while( $second_query->have_posts() ) : $second_query->the_post();
$titlechars = 45; // Character Limit
$posttitle = get_the_title();
$modtitle = substr($posttitle, 0, $titlechars);
$contentchars = 120; // Character Limit
$postcontent = get_the_excerpt();
$modcontent = substr($postcontent, 0, $contentchars);
echo \'<article \';
echo \' \' . post_class(\'\',false) . \' \';
echo \'>\';
?>
<?php
if( get_field(\'image\') ):
$attachment_id = get_field(\'image\');
$size = \'customfeatins\'; // (thumbnail, medium, large, full or custom size)
$image = wp_get_attachment_image_src( $attachment_id, $size );
echo \'<a href="\' . get_permalink() . \'"><img src="\' . $image[0] . \'" alt="\' . get_the_title() .\'" width="136" height="90" /></a>\';
?>
<?php else : ?>
<?php echo \'<a href="\' . get_permalink() . \'"><img src="\'. get_template_directory_uri() .\'/assets/img/content/bf-default.gif" alt="bf-default" width="136" height="90" /></a>\' ?>
<?php endif; ?>
<?php
echo \'
<div class="right-content">
<h3><a class="purple" href="\' . get_permalink() . \'">\' . $modtitle .\'</a></h3>
<p class="date">\' . get_the_date() .\'</p>
<p>\' . $modcontent . \'… <a href="\' . get_permalink() . \'">More ›</a></p>
</div>
</article>\';
?>
<?php
/* PageNavi at Bottom */
if (function_exists(\'wp_pagenavi\')){wp_pagenavi();}
// FOR PAGINATION - reassign the $wp_query variable to what is was originally and then reset the query back to start.
$wp_query = null;
$wp_query = $temp;
?>
<?php
endwhile;
endif;
wp_reset_postdata(); // to reset the loop
?>
</div><!-- [END] feed -->
我搜索了这里发布的问题和wp论坛,没有找到任何专门针对儿童类别的内容。
任何帮助都将不胜感激!!!
提前谢谢你。