wordpress导航中的自定义博客页面下一页和上一页不起作用

时间:2018-04-20 09:56:58

标签: wordpress custom-pages

我尝试使用导航创建自定义博客页面。没有导航,一切正常。我已经尝试修复了pagenation问题,但下面的工作无效是我的自定义页面模板的代码。

     <?php /*
    Template Name: My Blog Page
    */
    get_header();
    ?>
    <div class="container-fluid"><div class="row bkg-grey"><div class="container"><div class="row">
<div class="col-md-8"><div class="row">
    <?php
    $args = array( 'post_type' => 'post');
if ( have_posts() ) : 
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  ?>
 <div class="col-md-12"><div class="row lwp-posts">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="col-md-4"><div class="row">
<?php 
if ( has_post_thumbnail() ) {
the_post_thumbnail('homepage-thumb',array('class' => 'img-responsive' ) );
} ?></div></div>
<div class="col-md-8"><div class="row">
<div class="rjs-post-title"><h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2></div>
<div class="rjs-post-meta"><span>Posted on :<?php the_time( 'j M Y' ); ?></span><span>Posted by : <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a></span><span itemprop="interactionCount" content='UserComments: <?php comments_popup_link( '0', '1', '%' ); ?> '>Comments : <?php comments_popup_link( '0', '1', '%' ); ?></span><span>Category : <?php the_category(', '); ?></span></div>
<?php the_excerpt(); ?>
</div></div>
<?php edit_post_link(); ?>
<?php wp_link_pages(); ?>
</article></div></div>
<?php endwhile; ?>
 <nav class="navigation index">
<div class="alignleft"><?php next_posts_link( 'Older Entries' ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Newer Entries' ); ?></div>
</nav>
</div></div>
<?php else :  endif; ?>
<div class="col-md-4"><div class="row">
<?php if ( is_active_sidebar( 'home_right_1' ) ) : ?>
<div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'home_right_1' ); ?>
</div><!-- #primary-sidebar -->
<?php endif; ?>
</div></div></div></div></div></div>
<?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

您需要在查询参数中添加一些参数:

$args = array(
  'post_type' => 'post',
  'posts_per_page' => 6,
  'paged' => $paged
);

如果您想自定义导航链接,请使用以下模式:

<nav class="navigation index">
  <?php 
    echo paginate_links( array(
        'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
        'total'        => $query->max_num_pages,
        'current'      => max( 1, get_query_var( 'paged' ) ),
        'format'       => '?paged=%#%',
        'show_all'     => false,
        'type'         => 'plain',
        'end_size'     => 2,
        'mid_size'     => 1,
        'prev_next'    => true,
        'prev_text'    => sprintf( '<i></i> %1$s', __( 'Newer Posts', 'text-domain' ) ),
        'next_text'    => sprintf( '%1$s <i></i>', __( 'Older Posts', 'text-domain' ) ),
        'add_args'     => false,
        'add_fragment' => '',
    ) );
  ?>
</nav>