[英]Get next_post_link which is Sticky?
我正在嘗試使用以下標題來獲取下一篇粘性文章的鏈接:
<h2><?php next_post_link('%link') ?></h2>
我嘗試傳遞TRUE
參數,但這僅過濾分類法而不是粘性帖子。
在next_post_link中沒有選擇僅獲得粘性帖子的選項(如果我錯了,請糾正我)。 您需要在此處自定義導航。 首先,您需要將所有即時貼發布到數組中,然后再進行下一篇鏈接:
// get all sticky posts
$sticky = get_option('sticky_posts');
// if there are any
if (!empty($sticky)) {
// newest IDs first, optional
rsort($sticky);
$args = array(
'post__in' => $sticky
);
$postlist = get_posts();
$posts = array();
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post();
$posts[] = get_the_ID();
}
//wp_reset_postdata(); uncomment this, if this is a nested loop
$current = array_search($post->ID, $posts);
$prevID = $posts[$current-1];
$nextID = $posts[$current+1];
// Link for previous post
if (!empty($prevID)) {
echo '<div><a href="'. get_permalink($prevID) .'">Prev</a></div>';
}
// Link for next post
if (!empty($nextID)) {
echo '<div><a href="'. get_permalink($nextID) .'">Next</a></div>';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.