在 WordPress 的静态页面中添加下一个和上一个按钮?

发布于 2024-09-26 11:54:33 字数 617 浏览 0 评论 0原文

我正在尝试将下一个和上一个按钮添加到我的 WordPress 网站上的静态页面。

我已经能够找到一些有关如何将这些按钮添加到您的博客文章中的内容,但无法找到有关静态页面的类似内容。

我想添加下一个和上一个按钮以显示在我网站上所有父页面内的子页面上,这样您就可以使用链接导航到位于同一父页面内的下一个/上一个页面。

有谁知道我该如何做这个或任何可以帮助我的插件?

——

多亏了markratledge,我几乎已经搞定了,但我只是遇到了一个问题。

似乎下一个和上一个链接几乎按照我想要的方式工作,但是当我想匹配我的页面排序顺序时,它们会按字母顺序排列。

这是我尝试过的,但它没有似乎不起作用

$pagelist = get_pages('child_of='.$post->post_parent.'sort_column=menu_order');

似乎我只是发现它丢失了&...应该看起来像这样。

$pagelist = get_pages('child_of='.$post->post_parent.'&sort_column=menu_order');

I'm trying to add next and previous buttons to the static pages on my wordpress site.

I've been able to find some content on how to add these buttons to your blog post but haven't been able to find anything like this regarding static pages.

I'd like to add next and previous buttons to appear on the child pages within all the parent pages on my site, so you'd be able to use a link to navigate to the next/previous page located within the same parent.

Does anyone know how I could go about doing this or of any plugin that might help me out?

--

Thanks to markratledge, I've almost got it, but I just having one problem.

It seems the next and previous links are working almost how I'd like but they are coming in in alphabetical order when I want to to match the order I've got my pages ordered in.

this is what I've tried but it doesn't seem to work

$pagelist = get_pages('child_of='.$post->post_parent.'sort_column=menu_order');

Seems I just figured it out was missing &... should look like this.

$pagelist = get_pages('child_of='.$post->post_parent.'&sort_column=menu_order');

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

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

发布评论

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

评论(1

维持三分热 2024-10-03 11:54:33

这应该可以从 WordPress Codex 中获得(下一个和上一个链接 « WordPress Codex)。

排除 get_pages 中带有参数的页面:http://codex.wordpress.org/Function_Reference /get_pages

(或者这个插件 http://wordpress.org/extend/plugins/下一页/):

<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
   $pages[] += $page->ID;
}

$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"
  title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>" 
 title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div>

This should work, from the Wordpress Codex (Next and Previous Links « WordPress Codex).

Exclude pages with parameters in get_pages: http://codex.wordpress.org/Function_Reference/get_pages

(Or this plugin http://wordpress.org/extend/plugins/next-page/):

<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
   $pages[] += $page->ID;
}

$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"
  title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>" 
 title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文