2017-08-30 130 views
0

試圖弄清楚如何從我在此處找到的無限循環代碼中完全排除類別:http://wplancer.com/infinite-next-and-previous-post-looping-in-wordpress/。評論中有一些線索,但我不確定如何實際將它正確地集成到代碼中。我嘗試添加我想在此行中排除的類別ID,例如'get_adjacent_post(false,'5',true')',但它似乎沒有任何影響。在此先感謝您的幫助!從Wordpress中排除相鄰帖子無限循環排除類別

<?php 
/** 
* Infinite next and previous post looping in WordPress 
*/ 
if(get_adjacent_post(false, '', true)) { 
    previous_post_link('%link', '&larr; Previous Post'); 
} else { 
    $first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post(); 
     echo '<a href="' . get_permalink() . '">&larr; Previous Post</a>'; 
    wp_reset_query(); 
}; 

if(get_adjacent_post(false, '', false)) { 
    next_post_link('%link', 'Next Post &rarr;'); 
} else { 
    $last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post(); 
     echo '<a href="' . get_permalink() . '">Next Post &rarr;</a>'; 
    wp_reset_query(); 
}; ?> 

回答

0

管理通過安裝這個插件來解決這個問題:https://wordpress.org/plugins/ambrosite-nextprevious-post-link-plus/,然後使用此頁上提供的網址查詢風格的字符串代碼:http://www.ambrosite.com/plugins/next-previous-post-link-plus-for-wordpress

最終代碼看起來像這樣(請確保您有安裝插件或它不會工作):

<?php previous_post_link_plus('order_by=post_date&meta_key=&loop=1&thumb=0&max_length=0&in_same_cat=0&ex_cats=24,11,10,8,9,12&ex_cats_method=strong&num_results=1&echo=1'); ?> 
 
<?php next_post_link_plus('order_by=post_date&meta_key=&loop=1&thumb=0&max_length=0&in_same_cat=0&ex_cats=24,11,10,8,9,12&ex_cats_method=strong&num_results=1&echo=1'); ?>