true, 'post__in' => $related_posts_ID, 'orderby' => 'rand', 'ignore_sticky_posts' => true ) ); if( !$query->have_posts() ) return; ?> ID ); if( $tags = get_the_tags( $post ) ){ $tags_ID = array(); foreach( $tags as $tag ) $tags_ID[] = $tag->term_id; $posts = get_posts( array( 'tag__in' => $tags_ID, 'exclude' => $exclude_ID, 'orderby' => 'rand', 'fields' => 'ids', 'numberposts' => $number ) ); } if( count( $posts ) < $number && $cats = get_the_category( $post ) ){ $cats_ID = array(); foreach( $cats as $cat ) $cats_ID[] = $cat->term_id; $_posts = get_posts( array( 'category__in' => $cats_ID, 'exclude' => array_merge( $exclude_ID, $posts ), 'orderby' => 'rand', 'fields' => 'ids', 'numberposts' => $number - count( $posts ) ) ); $posts = array_merge( $posts, $_posts ); } if( count( $posts ) < $number ){ $_posts = get_posts( array( 'exclude' => array_merge( $exclude_ID, $posts ), 'orderby' => 'rand', 'fields' => 'ids', 'numberposts' => $number - count( $posts ) ) ); $posts = array_merge( $posts, $_posts ); } return $posts; } if ( !function_exists( 'Bing_related_posts_loop' ) ) : /** * 相关文章样式 */ function Bing_related_posts_loop(){ ?>
  • >
  • true, 'post__in' => $related_posts_ID, 'orderby' => 'rand', 'ignore_sticky_posts' => true ) ); while( $query->have_posts() ){ $query->the_post(); Bing_related_posts_loop(); } wp_reset_postdata(); wp_die(); } add_action( 'wp_ajax_related_posts_refresh', 'Bing_related_posts_refresh' ); add_action( 'wp_ajax_nopriv_related_posts_refresh', 'Bing_related_posts_refresh' ); //End of page.