php - 如何显示同一类别wordpress的第一条和最后一条记录?
问题描述
我有一个功能,它应该显示指向与拉动记录相同类别的第一个或最后一个记录的链接,但是通过单击“前进”或“后退”按钮,它会在两个记录之间切换,尽管有在 category 中是三个,或者,在一个记录所在的类别中,抛出另一个类别的记录。我需要他,在没有条目之后,他可以从最后一个记录切换到相同类别的第一条记录,从第一条记录切换到最后一条,因为有一个带有相同类别的后退按钮
function da_the_adjacent_post_link( $course = '' ){
global $post;
$course = ( $course == 'prev' ) ? true : false;
$order = ( $course ) ? 'DESC' : 'ASC';
$class = ( $course ) ? 'prev' : 'next';
$link = get_adjacent_post_link( '%link', '%title', true, '', $course );
if ( ! $link ){
$term = get_the_terms( $post->ID, 'category' );
$term = $term[0];
$article = get_posts([
'post_type' => portfolio,
'post_per_page' => 1,
'exclude' => $post->ID,
'category' => $term->term_id,
'order' => $order
]);
if ( empty($article) )
return false;
else
$article = $article[0];
$link = sprintf( '<a href="' . get_the_permalink($article->ID) . '"> ');
}
echo $link;
}
if( get_adjacent_post(true,'',true) ) {
previous_post_link('%link', '<div class="icon-button">');
} else {
da_the_adjacent_post_link( $course = '' ); ?>
};
if( get_adjacent_post(true, '', false)){
next_post_link('%link', ' <div class="icon-button">')
} else {
da_the_adjacent_post_link( $course = '' ); ?>
};
解决方案
推荐阅读
- variables - 跨模块的 Terraform 输出
- c++ - 为什么 QTextDocument 背景颜色只改变一次?
- laravel - 如何用查询中的字符串替换字段的空值
- jquery - 在 sitefinity 升级脚本发生冲突后
- python - 如何将数据集 id 传递给 python 的 bigquery 客户端
- r - 使用重采样在 Tidymodels 中预先分配虚拟变量级别
- javascript - 为什么 IFrame 不会在单击容器 div 时加载?
- python - 查找 txt 文件中出现次数最多的电子邮件地址
- symfony - 防止 Doctrine 将 ArrayCollection 用于关系
- ios - 通过 indexpath 使用结构和数据制作 tableView 单元格