【发布时间】:2018-01-10 14:27:45
【问题描述】:
我在 localhost 中测试 WordPress,发布文章以查看如何工作,一切都很好,直到我不得不在一页中有很多文章,我不得不使用分页转到第二页,然后我点击了第二页,但我得到了一个 404 Not Found 页面。
我找了大约 2-3 个小时,尝试了每个函数,每个示例,但结果都是一样的。
首页为静态首页,称为Landing,所有文章均设置为Blog页面。
我的 index.php 中的 php 代码:
<div class="container-medium">
<div class="row">
<?php while(have_posts()) : the_post(); ?>
<div class="col-xs-12 col-sm-12 col-md-12">
<?php the_post_thumbnail('post-thumbnail', array( 'class' => "img-responsive desaturate attachment-post-thumbnail")); ?>
<h3 class="blog-post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="row">
<div class="col-sm-12"><p class="blog-post-text"><?php echo get_excerpt(); ?></p></div>
<div class="col-sm-12"><a class="btn btn-sm btn-readmore" href="<?php echo get_permalink(); ?>">Read more <i class="icon-right-open"></i></a></div>
</div>
<hr class="dotted">
</div>
<?php endwhile; wp_reset_query(); ?>
</div> <!-- end .row -->
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div> <!-- end .container-medium -->
我阅读了一堆类似的问题,但没有得到我想要的结果。
谢谢!
PS:PHP初学者
【问题讨论】:
标签: php wordpress pagination