获取“第 X 页,共 Y 页” Wordpress 中的消息单.php

发布于 2024-12-05 21:44:16 字数 361 浏览 6 评论 0原文

我想知道如何才能使 ie “第 2 页,共 13 页” 出现在 Wordpress 的 single.php 页面的底部。

假设用户单击首页上的帖子标题,当使用 single.php 打开该帖子时,用户会看到他所在的页面(以及总共有多少个页面)。因此,如果他选择查看第三篇帖子,则会显示“第 3 篇帖子,共 13 篇”。。如果他随后单击“下一个”或“上一个”,他会得到“第 2 个帖子(共 13 个)”或“第 4 个帖子(共 13 个)”等信息。

我已经设法在首页上做到这一点,但似乎无法让它在 single.php 上正常工作

。我想要这样做的原因是在上一个箭头和下一个箭头之间有消息。

I'm wondering how i can make i.e 'Page 2 of 13' appear on the bottom of Wordpress' single.php page.

Let's say a user clicks a post title on the front page, and when it's opened with single.php the user sees what page he's on (and also how many are total). So if he chooses to view the third post it would say 'Post 3 of 13'. If he then clicks Next or Previous, he gets 'Post 2 of 13', or 'Post 4 of 13' and so on.

I've managed to do this on the front page, but can't seem to get it working properly on single.php

The reason i want this is to have the message between a prev and next arrow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ヤ经典坏疍 2024-12-12 21:44:16

您是否尝试过

posts_nav_link();

以前的帖子();

下一个帖子();

请参阅此处

Have you tried

posts_nav_link();

previous_post();

next_post();

Refer here

痴骨ら 2024-12-12 21:44:16

这是一个可以在侧边栏中使用的简单方法:

<?php
$page_id = $post->ID;
$page_parent = $post->post_parent;
if ($page_parent) { // there's a parent page, get the children
$args = array(
'parent' => $page_parent,
'child_of' => $page_parent,
'hierarchical' => 0,
'sort_column' => 'menu_order'
);
}
else { // no parent, so just get top level pages
$args = array(
'parent' => 0,
'sort_column' => 'menu_order'
);
}
$my_pages = get_pages($args);
while ($page = current($my_pages)) { // find this page's position in the page array
if ($page->ID == $page_id) {
echo key($my_pages) + 1;
}
next($my_pages);
}
$result = count($my_pages);
echo " of " . $result;
?>

Here's an easy way that will work in your sidebar:

<?php
$page_id = $post->ID;
$page_parent = $post->post_parent;
if ($page_parent) { // there's a parent page, get the children
$args = array(
'parent' => $page_parent,
'child_of' => $page_parent,
'hierarchical' => 0,
'sort_column' => 'menu_order'
);
}
else { // no parent, so just get top level pages
$args = array(
'parent' => 0,
'sort_column' => 'menu_order'
);
}
$my_pages = get_pages($args);
while ($page = current($my_pages)) { // find this page's position in the page array
if ($page->ID == $page_id) {
echo key($my_pages) + 1;
}
next($my_pages);
}
$result = count($my_pages);
echo " of " . $result;
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文