马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
在WordPress中,你可以使用`get_adjacent_post()`函数来获取上一篇和下一篇文章的信息,并根据是否存在这些文章来表现相应的链接和提示。以下是一个示例代码,它会查抄上一篇和下一篇文章是否存在,并相应地表现链接或提示信息:
- <?php
- // Obtain the previous article
- $prev_post = get_adjacent_post(true, '', true);
- $prev_title = $prev_post ? $prev_post->post_title : '';
- $prev_link = $prev_post ? get_permalink($prev_post->ID) : '';
- // Get the next article
- $next_post = get_adjacent_post(true, '', false);
- $next_title = $next_post ? $next_post->post_title : '';
- $next_link = $next_post ? get_permalink($next_post->ID) : '';
- // wodepress.com Display the link and title of the previous article
- if ($prev_post) {
- echo '<li><a href="' . esc_url($prev_link) . '" rel="prev">' . esc_html($prev_title) . '</a> 上一篇</li>';
- } else {
- echo '<li>没有上一篇文章</li>';
- }
- // Display the link and title of the next article
- if ($next_post) {
- echo '<li><a href="' . esc_url($next_link) . '" rel="next">' . esc_html($next_title) . '</
复制代码 |