0

我已经看到了与此非常相似的帖子以及许多其他示例,例如此处的自定义函数的 wordpress 文档: 下一个/上一个帖子链接的函数参考

但是,我的示例位于 Storefront (woothemes) 主题中的自定义函数中,因此在不破坏功能的情况下以正确的方式合并“$in_same_term = true”时遇到了麻烦。这是主题中“post.php”文件中的(原始)代码,我认为我需要以某种方式合并“$in_same_term = true”,...

    if ( ! function_exists( 'storefront_paging_nav' ) ) {
/**
 * Display navigation to next/previous set of posts when applicable.
 */
function storefront_paging_nav() {
    global $wp_query;
        $args = array(
        'type'      => 'list',
        'next_text' => _x( 'Next', 'Next post', 'storefront' ) . '&nbsp;<span class="meta-nav">&rarr;</span>',
        'prev_text' => '<span class="meta-nav">&larr;</span>&nbsp' . _x( 'Previous', 'Previous post', 'storefront' ),
        );

    the_posts_pagination( $args );
}
    if ( ! function_exists( 'storefront_post_nav' ) ) {
/**
 * Display navigation to next/previous post when applicable.
 */

function storefront_post_nav() {

    $args = array(
        'next_text' => '%title &nbsp;<span class="meta-nav">&rarr;</span>',
        'prev_text' => '<span class="meta-nav">&larr;</span>&nbsp;%title',
        );
    the_post_navigation( $args );
}
    }

我想我可能会很接近,因为大量搜索揭示了相同类型的信息,我只是没有正确整合它......

提前感谢您提供有关如何最好地整合此功能的任何建议!

4

2 回答 2

1

您只需添加函数'in_same_term' => true数组storefont_post_nav

function storefront_post_nav() {
    $args = array(
        'next_text' => '%title &nbsp;<span class="meta-nav">&rarr;</span>',
        'prev_text' => '<span class="meta-nav">&larr;</span>&nbsp;%title',
        'in_same_term' => true,   
    );
}

可以在数组中添加其他选项。你可以看看这里https://developer.wordpress.org/reference/functions/the_post_navigation/

于 2016-06-27T09:13:59.010 回答
0

好的,所以我的主要问题是试图将代码合并到错误的位置 - 我所要做的就是更改next_post_link此文件中的参数:wp-includes/link-template.php. (不是post.php我试图做的文件)。

值得注意的是,对于每个下一个和上一个链接,有 2 组参数$in_same_term = false需要更改为true.

现在可以享受美食了!

于 2015-10-21T09:21:32.310 回答