【发布时间】:2014-06-22 21:38:00
【问题描述】:
我需要在帖子分页的其他页面上显示 the_content()。例如。第一页是一个名为“索引”的额外字段。第 2 页是“摘要”,第 3 页显示作者信息。在第 4 页 the_content 应该开始了。
问题是 wordpress 开始计算页数,并且在第 4 页上,the_content 就像在第 4 页上一样显示(所以在 的 4 次之后)。
我这样做了:
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (!preg_match('#/\d+/?#', $url)) {
the_field("index");
} elseif(false !== strpos($url,'/2/')) {
get_the_author_meta('first_name').' '.get_the_author_meta('last_name');
} elseif(false !== strpos($url,'/3/')) {
the_field("abstract");
} else {
the_content();
}
但是,正如我所说,the_content() 从第 4 页开始。我知道它应该这样做。 我怎么能做到第 4 页就像 the_content() 的第 1 页一样。
澄清更新:
我想在我的主题文件content-single.php中放出the_content()来在前端展示我的文章。我已启用分页功能,因此 Wordpress 会在找到 时对我的文章进行分页。这是原生的 Wordpress 行为。
但我想在 the_content() 之前添加一些额外的内容。
Page 1: Index
Page 2: Abstract
Page 3: Author
Page 4: START the_content() page 1
Page 5: the_content() page 2
Page 6: the_content() page 3
等等……
我正在使用上面编写的代码执行此操作。我检查我们在哪一页。 ($url,'/3/') 是第 3 页。
即使我检查第 4 页(在 else-part 中)并在这里放出 the_content(),wordpress 也会放出 the_content() 的第 4 页,所以 4 次后的部分 。我没有从第 4 页的 the_content() 开始,但它从第 1 页开始但不显示它。内部页面计数器以某种方式运行。
如何在第 4 页启动 the_content()?或者我怎样才能防止 Wordpress 计算页数?
【问题讨论】:
标签: php wordpress pagination