Halo Eveyone,现在正在执行自定义wordpress任务,以便在没有插件的自定义类别模板页面上进行分页。我在XAMPP上执行此操作。我尝试了很多代码,但分页不起作用
这是我的代码。
对于index.php,我通过链接显示了所有列表类别
<?php
$categories = get_categories();
foreach($categories as $category) {
$category_link = get_category_link($category->cat_ID);
echo '<a href="' . esc_url( $category_link ) . '"><li>' . $category->name . '</li></a>';
}
wp_reset_query();
?>
,列表显示如下
http://localhost/mywptask/category/category_2/
在category.php文件中
<?php
$currCat = get_category(get_query_var('cat'));
$cat_name = $currCat->name;
$cat_id = get_cat_ID( $cat_name );
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=2&post_type=post&paged='.$paged.'&cat='.$cat_id);
if ($wp_query->have_posts()) :
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="title_name"> <?php the_title(); ?> </div>
<div class="column_content"> <?php echo the_excerpt(); ?> </div>
<?php endwhile; ?>
<div class="pageNav04c">
<?php category_pagination();?>
</div>
<?php else : ?>
Category not found
<?php endif;
wp_reset_query();?>
我在functions.php中为显示分页进行了自定义设置
<?php
function category_pagination() {
global $wp_query;
$big = 999999999;
$paged = paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'prev_next' => true,
'prev_text' => __('Previous'),
'next_text' => __('Next'),
'type' => 'list',
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => '',
'total' => $wp_query->max_num_pages
));
$arr = array(
'<li>' => '<li class="other">',
"'" => '"'
);
echo strtr($paged, $arr);
}
按下链接的下一个按钮转到该链接
http://localhost/mywptask/category/category_2/page/2/
,它不起作用...错误显示“找不到页面” ..我不知道。我的错误在哪里。请帮助我