web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

wordpress技巧如何获取上一篇下一篇文章链接

678 ℃

wordpress建站如何利用自身函数获取上一篇下一篇文章链接,下面web建站小编给大家简单介绍一下!

函数原型:

get_adjacent_post_link( string $format, string $link, bool $in_same_term = false, int[]|string $excluded_terms = '', bool $previous = true, string $taxonomy = 'category' ): string

参数说明:

参数描述
$format占位符 %link 表示整个 a 标签。比如:’%link ->’,最后生成的结果类似:<a></a>->。
$linka 标签内部内容。占位符 %title 表示文章标题。如果不使用 %title,生成的 a 标签里也就不会有文章标题了。
$in_same_term是否要求是同一分类下的
$previoustrue 上一篇,false 下一篇。
$taxonomy默认 ‘category’,与 $in_same_term 配合使用。

函数源码:

function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  if ( $previous && is_attachment() ) {
    $post = get_post( get_post()->post_parent );
  } else {
    $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
  }

  if ( ! $post ) {
    $output = '';
  } else {
    $title = $post->post_title;

    if ( empty( $post->post_title ) ) {
      $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
    }

    /** This filter is documented in wp-includes/post-template.php */
    $title = apply_filters( 'the_title', $title, $post->ID );

    $date = mysql2date( get_option( 'date_format' ), $post->post_date );
    $rel  = $previous ? 'prev' : 'next';

    $string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
    $inlink = str_replace( '%title', $title, $link );
    $inlink = str_replace( '%date', $date, $inlink );
    $inlink = $string . $inlink . '</a>';

    $output = str_replace( '%link', $inlink, $format );
  }

  $adjacent = $previous ? 'previous' : 'next';

  return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );
}

WordPress如何判断当前文章是否是密码保护文章

WordPress版本如何使用str_starts_with和str_ends_with函数

WordPress如何显示当前文章的评论个数

wordpress如何显示下个评论链接

wordpress教程如何输出用于回复评论的隐藏输入html

标签: wordpress函数 wordpress获取文章链接

上面是“wordpress技巧如何获取上一篇下一篇文章链接”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_4494.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计1384个字,预计阅读时长10分钟

基金从业资格考试题库

一站式备考基金从业资格考试,收录2021-2025年模拟题库!呱呱工具箱

AI工作站

收录全球3800+ 款各行各业AI应用,轻轻松松做事!

生活小工具

收录了万年历、老黄历、八字智能排盘等100+款小工具!生活小工具
上一篇: win7系统设置防火墙报0x8007042c错误解决方法
下一篇: 国家送给全国人民的9个免费神器(赶紧收藏)
x 打工人ai神器