[英]Wordpress: next page on pagination always return to index.php
我试图通过使用WP_Query向我的自定义页面添加简单的分页。 但是,单击下一页链接后,它将始终转到index.php(因为我的主题中仍然没有404.php)
这是我的自定义页面的代码,其中包含分页
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=2&cat=2'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="col-md-3 col-sm-4 article-list" data-sr='enter bottom, move 50px, over 0.5s'>
<a href="<?php the_permalink(); ?>"><p class="article-link-img"><?php the_post_thumbnail('small-thumbnail'); ?></p>
<p class="article-link-title"><?php the_title(); ?></p></a>
</div>
<?php endwhile; ?>
<nav>
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</nav>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
这是我的index.php中的代码
<?php get_header(); ?>
<div class="container index-section">
<section>
<div class="row">
<div class="col-md-12">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<p><?php the_content(); ?></p>
<?php endwhile; else: ?>
<h1 class="index-error-message"><?php _e('Sorry, this post does not exist.'); ?></h1>
<h2 class="single-article-popular-title">Popular Articles</h2>
<?php
$topBlogs = new WP_Query('orderby=rand&cat=3&posts_per_page=4');
if ($topBlogs -> have_posts() ) :
while ($topBlogs -> have_posts() ) : $topBlogs -> the_post(); ?>
<div class="col-md-3 col-sm-3 col-xs-6 single-article-popular-list">
<a href="<?php the_permalink(); ?>"><p><?php the_post_thumbnail('small-thumbnail'); ?></p>
<p class="single-article-popular-link-title"><?php the_title(); ?></p></a>
</div>
<?php endwhile; else: ?>
<h3>No content found</h3>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</section>
</div>
<?php get_footer(); ?>
我试图找出问题所在,但仍然没有解决方案。 我也尝试过使用WP_PageNAVi插件,但是仍然有相同的结果。
这是我的自定义页面的完整代码
<?php get_header(); ?>
<div class="article-featured">
<div class="container">
<section>
<div class="row">
<?php
$featuredBlogs = new WP_Query('cat=4&posts_per_page=1');
if ($featuredBlogs -> have_posts() ) : while ($featuredBlogs -> have_posts() ) : $featuredBlogs -> the_post(); ?>
<div class="col-md-12 article-featured-descr">
<a href="<?php the_permalink(); ?>"><p class="article-featured-descr-text" data-sr='enter bottom, move 50px, over 0.5s'>Featured article</p>
<h1 data-sr='enter bottom, move 50px, wait 0.3s, over 0.5s'><?php the_title(); ?></h1>
<img src="/ecteciant/wp-content/themes/ecteciant/files/images/article/no-article.png" alt="no article" data-sr='enter bottom, move 50px, wait 0.6s, over 0.5s'></a>
</div>
<?php endwhile; else: ?>
<div class="col-md-12 article-featured-descr">
<p class="article-featured-descr-text" data-sr='enter bottom, move 50px, over 0.5s'>No featured article found</p>
<img src="/ecteciant/wp-content/themes/ecteciant/files/images/article/no-article.png" alt="no article" data-sr='enter bottom, move 50px, wait 0.3s, over 0.5s'>
</div>
<?php endif; ?>
</div>
</section>
</div>
</div>
<div class="container">
<section>
<div class="row">
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=2&cat=2'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<div class="col-md-3 col-sm-4 article-list" data-sr='enter bottom, move 50px, over 0.5s'>
<a href="<?php the_permalink(); ?>"><p class="article-link-img"><?php the_post_thumbnail('small-thumbnail'); ?></p>
<p class="article-link-title"><?php the_title(); ?></p></a>
</div>
<?php endwhile; ?>
<nav>
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</nav>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
<div class="col-md-12 article-not-found">
<img src="/ecteciant/wp-content/themes/ecteciant/files/images/article/submit-article.png" alt="submit article" data-sr='enter bottom, move 50px, over 0.5s'>
<p data-sr='enter bottom, move 50px, wait 0.3s, over 0.5s'>What do you think about <b>"A"</b>? How about <b>"B"</b>?<br/>Send your thoughts to <a href="mailto:article@ecteciant.com?Subject=New%20Article%20Inquiry">article@ecteciant.com</a>, we accept from <b>A to Z.</b> Our team will review your submission.<br/>Stand a chance to be <b>FEATURED</b> in our page.</p>
</div>
</div>
<!--<iframe src="https://www.facebook.com/plugins/share_button.php?href=https%3A%2F%2Fbudilokawijaya.com&layout=button_count&mobile_iframe=true&width=86&height=20&appId" width="86" height="20" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>
<a href="https://twitter.com/intent/tweet?button_hashtag=ecteciantID" class="twitter-hashtag-button" data-related="budi_czras,ecteciantID" data-url="http://ecteciant.com">Tweet #ecteciantID</a>-->
</section>
</div>
<?php get_footer(); ?>
我刚刚从另一个解决该问题的论坛上找到了答案。
通过修改“阅读博客”页面最多显示= 1的管理员,解决了该问题。 但是不知道为什么能解决这个问题,我也不知道这样做是否有任何弊端。
至少这解决了问题。
如果有人知道更好的解决方案,请发布您的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.