这真令人沮丧。所以我设法让分页在主页上工作了一段时间,但没有再次破坏。我目前设置了首页设置以显示静态首页。然后,我创建了一个名为“Home”的页面,该页面使用的是homepage.php:
<?php
/* Template Name: Homepage */
$paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;
?>
<?php get_header(); ?>
<?php if ( $paged == 1 ) : ?>
<div class="large-12 columns" id="primary">
<?php $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1; $wp_query = new WP_Query( array( 'posts_per_page' => 1, 'ignore_sticky_posts' => 1, 'post__in' => get_option( 'sticky_posts' ), 'paged' => $paged ) ); if ( $wp_query -> have_posts() ) : while ( $wp_query -> have_posts() ) : $wp_query -> the_post(); ?>
<!-- Sticky Content Goes Here-->
<?php endwhile; wp_reset_postdata(); endif; ?>
</div>
<?php endif; ?>
<div class="large-8 columns">
<?php $paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1; $wp_query = new WP_Query( array( 'posts_per_page' => 10, 'ignore_sticky_posts' => 1, 'paged' => $paged ) ); if ( $wp_query -> have_posts() ) : while ( $wp_query -> have_posts() ) : $wp_query -> the_post(); ?>
<!-- Post Content Goes Here -->
<?php endwhile; ?>
<?php if ( get_next_posts_link() || get_previous_posts_link() ) : ?>
<article class="content hide-for-small-only">
<?php the_posts_pagination(); ?>
</article>
<article class="content show-for-small-only">
<?php the_posts_pagination( array( 'prev_text' => '▲', 'next_text' => '▲' ) ); ?>
</article>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
任何人都可以告诉我为什么每次我点击下一个或一个数字,它指示我回到www.example.com/而不是www.example.com/page/2
是的,我确实意识到代码有点多了。
答案 0 :(得分:0)
尝试使用以下代码:
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('<i class="fa fa-angle-double-left"></i>'),
'next_text' => __('<i class="fa fa-angle-double-right"></i>'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<div class='col-md-12'><nav class='custom-pagination pagination'>";
echo $paginate_links;
echo "</nav></div>";
}
}
可以在下面调用,在while循环结束时显示分页。
if (function_exists(custom_pagination)) {
custom_pagination($the_query->max_num_pages,"",$paged);
}
$ paged你从你自己的
的wp_query上面得到了