Php 如何根据Wordpress中的类别导航到下一篇或上一篇文章?

Php 如何根据Wordpress中的类别导航到下一篇或上一篇文章?,php,wordpress,Php,Wordpress,我发现了许多类似的问题,但我不擅长PHP,我不想去修改代码几十次。我很感激如果有人能帮助我,使这个代码导航下一个和上一个基于相同的类别,如动物,植物,非生物->3类,但每个职位导航在相同的类别在底部页面 这是主题文件中的当前代码。主题名称为作者,仅供参考 <?php global $post; $previous_post = get_adjacent_post( false, '', true ); $previous_text = esc_html__( 'Previous Pos

我发现了许多类似的问题,但我不擅长PHP,我不想去修改代码几十次。我很感激如果有人能帮助我,使这个代码导航下一个和上一个基于相同的类别,如动物,植物,非生物->3类,但每个职位导航在相同的类别在底部页面

这是主题文件中的当前代码。主题名称为作者,仅供参考

<?php

global $post;

$previous_post = get_adjacent_post( false, '', true );
$previous_text = esc_html__( 'Previous Post', 'author' );

if ( $previous_post == '' ) {
    $previous_text  = esc_html__( 'No Older Posts', 'author' );
    if ( get_option( 'show_on_front' ) == 'page' ) {
        $previous_url = get_permalink( get_option( 'page_for_posts' ) );
    } else {
        $previous_url = get_home_url();
    }
    $previous_link = '<a href="' . esc_url( $previous_url ) . '">' . esc_html__( 'Return to Blog', 'author' ) . '</a>';
}

$next_post  = get_adjacent_post( false, '', false );
$next_text  = esc_html__( 'Next Post', 'author' );

if ( $next_post == '' ) {
    $next_text  = esc_html__( 'No Newer Posts', 'author' );
    if ( get_option( 'show_on_front' ) == 'page' ) {
        $next_url = get_permalink( get_option( 'page_for_posts' ) );
    } else {
        $next_url = get_home_url();
    }
    $next_link = '<a href="' . esc_url( $next_url ) . '">' . esc_html__( 'Return to Blog', 'author' ) . '</a>';
}

?>
<nav class="further-reading">
    <div class="previous">
        <span><?php echo esc_html( $previous_text ); ?></span>
        <?php
        if ( $previous_post == '' ) {
            echo $previous_link;
        } else {
            previous_post_link( '%link' );
        }
        ?>
    </div>
    <div class="next">
        <span><?php echo esc_html( $next_text ); ?></span>
        <?php
        if ( $next_post == '' ) {
            echo $next_link;
        } else {
            next_post_link( '%link' );
        }
        ?>
    </div>
</nav>

我对堆栈溢出不太熟悉,但我想结束这个问题,因为我换了另一个主题。