我需要过滤WordPressss中的next_post_link()
和previous_post_link()
函数的帮助。我希望它仅显示下一个/上一个帖子,其答案与当前字段相同。
我在帖子类型上设置了一个自定义字段,该字段是$ post_object。
管理员为帖子创建内容,并从post_object drop down field
中选择类别。
这些next_post_link()
和previous_post_link()
按钮位于我的/single-featured_project/ (single-post_type)
页面的顶部。
感谢您的帮助:), 快乐编码
<?php
/**
* The template for displaying featured project single posts.
*
* @package understrap
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header();
?>
<?php
the_post();
$cat = '';
$cat = get_the_category();
if (is_array($cat))
$cat = $cat[0];
?>
<section class="featured-project-header" style="background-color: #13293C; padding-top: 6rem; padding-bottom: 1rem;">
<div class="container">
<div class="box" style="display: flex; align-items:center;">
<img style="max-height: 22px;" src="/wp-content/uploads/2018/09/Symbol-6-–-1@2x.png">
<span class="featured-project-title"><h1 class="mb-0"> <?php the_title();?></h1></span>
</div>
<h3 style="margin-left: 55px;" class="featured-project-location"><?php echo do_shortcode('[acf field="location"]'); ?></h3>
<!-- Displays Project Category to Filter By -->
<?php
$post_object = get_field('project_category');
if( $post_object ):
// override $post
$post = $post_object;
setup_postdata( $post );
?>
<?php the_title(); ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
<!-- Ends Project Category to Filter By -->
<div class="float-right"><?php next_post_link(); ?></div>
<div class="float-left"><?php previous_post_link(); ?></div>
</div>
</section>