2015-10-20 70 views
0

我看到一個非常類似的帖子這個和許多其他例子,如這裏自定義功能的WordPress的文檔: Function reference for next/prev post link修改博客頁面來自同一個類別只顯示帖子時按下下一個/上鍊接

然而,我的例子坐在內似乎是在店面(woothemes)主題範圍內的自定義功能等我有納入正確的方式「$ in_same_term = TRUE,」不破壞功能的麻煩。下面是代碼在我想我需要以某種方式納入「$ in_same_term =真」的主題中的「post.php中」文件(原料)有點...

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); 
} 
    } 

我想我可能是接近的搜索負荷已經揭示了同一種信息的,我只是不正確集成起來......

預先感謝如何最好地將這個功能有什麼建議!

+0

'the_posts_pagination()'沒有'in_same_term'參數...但是,像['nex_post_link'](https://codex.wordpress.org/Function_Reference/next_post_link)做... – rnevius

+0

@rnevius感謝那 - 你是說我應該能夠編寫一個單獨的功能(除了已有的「the_posts_pagination」功能)?或者我將它添加到function.php文件而不是這個post.php文件? – Pike800

回答

0

好了,所以我在這裏主要的問題是試圖將代碼在錯誤的地方 - 所有我需要做的就是改變此文件中的參數next_post_linkwp-includes/link-template.php。 (不是我正在嘗試執行的post.php文件)。

值得注意的是,每個下一個和上一個鏈接有2組參數,其中$in_same_term = false需要更改爲true

現在的作品一種享受!

+0

我強烈建議您不要修改核心WordPress的文件(即*什麼WP-包括/ *或*可溼性粉劑管理員/ *)。如果您將來更新WordPress,那麼您所做的任何更改都將被覆蓋。相反,請看看'the_post_pagination()'的工作方式,並在主題的模板文件中製作自己的版本。 – rnevius

0

你剛纔給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, 
    ); 
} 

可以在陣列中添加其他選項中添加'in_same_term' => true。您可以在這裏看看https://developer.wordpress.org/reference/functions/the_post_navigation/

相關問題