一般我们获取wordpress文章的上下篇都是用get_previous_post()与get_next_post()函数来获取,那么如何获取同分类下的上下篇文章呢,只需要给这俩函数加一个参数即可。

使用

get_previous_post(true)    get_next_post(true)

即可,获取到的就是一个post对象。

这里获取到的是分类1 or 2的文章,如果你想获取分类1 and 2的文章,那么得这样。

// Create a new filtering function that will add our where clause to the query  function date_filter_where( $where = '' ) {  global $post;  $where .= " AND post_date >= '".$post->post_date."'";  return $where;  }    //then create your own get previous post function which will take an array of categories eg:   // $cats = array('1','2');  function my_get_previous_post($cats){  global $post;  $temp = $post;  $args = array(  'posts_per_page' => 1,  'post_type' => 'post',  'post_status' => 'publish',  'category__and' => $cats  );  add_filter( 'posts_where','date_filter_where' );  $q = new WP_Query($args);  remove_filter( 'posts_where','date_filter_where' );  while ($q->have_posts()){  $q->the_post;  echo '<a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>';  }  $post = $temp;  wp_reset_query();  }

使用$cats = array(‘1′,’2’); my_get_previous_post($cats);


新软师兄 » WordPress 怎样获取同分类下文章的上一篇与下一篇
50T免费网盘资源大集合【持续更中~~~~】:点击查看

dase kand pornhan.mobi xvideo desi gay pcso 2pm result today pinoytvfriends.com where i can watch bad romeo كلام فى النيك wfporn.com قصص محارم حديثة busporn porngugu.mobi indian sexx vedios sex ka video noticieroporno.com himachal pradesh sex com
nero hentai hentaitgp.com ламия хентай www.mom xxx.com alohaporn.me sahara knite mature fucking tubepatrolporn.com bhabi sex indian girl sex gotporn.mobi xnxx family strocks ang probinsyano july 20 2022 full episode youtube pilipinoteleserye.com ano ang pambansang sasakyan ng pilipinas
احلي سكس محارم pornxporn.org نيك فلاحى multi.xnxx alohaporn.net telugu sex chart سكس قصيرات arabysexy.org نيك نقاب www assames sex com umora.info desi sexy bhabi 8teenx bukaporn.com india hot sex videos