我正在从头开始构建一个wordpress主题,我想在博客pag上显示分页,但它不起作用。
这是我的index.php
<?php get_header();?>
<div class="container-fluid" style="position: relative;">
<div class="row" style="display: flex; background-color: #F5F5F5;">
<div class="page-content col-md-9">
<div style="padding:0 80px">
<?php while (have_posts()):the_post(); ?>
<div class="col-md-4">
<div class="thumbnails">
<div class="date">
<div class="day">
<?php the_time('d'); ?>
</div>
<div class="month">
<?php the_time('F'); ?>
</div>
</div>
<img src=<?php the_post_thumbnail_url(); ?> alt="" width="400" height="300">
<div class="thumb-text">
<div class="excerpt"><?php the_excerpt(); ?></div>
<a href=<?php the_permalink(); ?> target="_blank"><?php the_title(); ?></a>
</div>
</div>
</div>
<?php endwhile ?>
</div>
<div><?php wp_numeric_posts_nav(); ?></div>
</div>
</div>
</div>
<?php get_footer();?>
我甚至尝试将功能调用放入循环但仍然无法正常工作 任何帮助或线索?
答案 0 :(得分:0)
要在博客页面中显示分页,您必须使用此功能:
<?php the_posts_pagination( array(
'mid_size' => 2,
'prev_text' => 'Previous',
'next_text' => 'Next'
) );
?>
答案 1 :(得分:0)
将此功能添加到你的functions.php
function theme_pagination($pages = '', $range = 3)
{
global $wp_query;
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
else { $paged = 1; }
$showitems = ($range * 2)+1;
if(empty($paged)) $paged = 1;
if($pages == '' && $pages != 0)
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class='pagination'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div>\n";
}
}
将其添加到index.php global $wp_query;
并使用theme_pagination($wp_query->max_num_pages);
代替wp_numeric_posts_nav();