【发布时间】:2014-09-01 05:46:09
【问题描述】:
我一直在用头撞墙试图解决这个问题,但似乎无法找到解决方案。我已将偏移量定义为 0,但在我的分页链接中,旧帖子的偏移量 + 1 只会导致错误页面。不太确定我哪里出错了。任何帮助将不胜感激。
这是我 page.php 文件中的所有代码...
<?php
$offset = $_GET['offset'] ? $_GET['offset'] : 0;
$page_title = $wp_query->post->post_title;
$total_posts = wp_count_posts()->publish;
if ( $page_title == "Blog" ) {
?>
<div id="blog_content">
<?php
if($_GET['message']){
echo "<div style='background-color:#d9ffd1; padding:10px; margin-bottom:20px;'>".stripslashes($_GET["message"])."</div>";
}
?>
<?php
$post_count = 0;
$args = array( 'numberposts' => 10, 'post_status' => "publish", "offset"=>$offset*10);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); $post_count++; ?>
然后是我的分页链接
<div style="font-size:12px;">
<div style="float:left; width:49%;">
<?php
the_post();
if ($offset > 0): ?>
<a href="<?php the_permalink()?>&offset=<?=$offset-1?>">← Newer Posts</a>
<?php endif; ?>
</div>
<div style="float:right; width:49%; text-align: right;">
<?php
$next_post = get_next_post();
if ($total_posts > $post_count + ($offset*10)): ?>
<a href="<?php the_permalink()?>&offset=<?=$offset+1?>">Older Posts →</a>
<?php endif; ?>
</div>
<div style="clear:both;"></div>
</div>
提前感谢任何人都可以提供的任何帮助
【问题讨论】:
-
只是出于好奇,你为什么不把这个发到
http://wordpress.stackexchange.com/ -
需要更多信息,错误页面是什么?错误页面的url是什么?
-
离题,属于wordpress.stackexchange.com。 旁注: 为什么在同一个 HTML 中使用单引号和双引号?
-
您是否仔细查看了 pre_get_posts() 和 found_posts() 函数调用?查看
http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination -
这句话是什么意思?
I have offset defined as 0 but in my pagination links offset+1 for older posts just leads to an error page.究竟是什么,你想达到什么目的? (offset = zero 不是这里的默认行为吗?get_option('posts_per_page');不是更容易工作吗?
标签: php wordpress pagination