- - - - - - - - + + + array('post', 'shuoshuo'), + 'post_status' => 'publish', + 's' => $search_query, + 'posts_per_page' => -1, + 'orderby' => 'relevance', + 'order' => 'DESC', + ); + + $all_results_query = new WP_Query($all_results_args); + + //结果 + $all_results = []; + $sticky_results = []; + $non_sticky_results = []; + + //分类置顶内容和非置顶内容 + if ($all_results_query->have_posts()) : + while ($all_results_query->have_posts()) : $all_results_query->the_post(); + if (in_array(get_the_ID(), $sticky_posts)) { + $sticky_results[] = $post; + } else { + $non_sticky_results[] = $post; + } + endwhile; + endif; + wp_reset_postdata(); + + //合并结果,优先展示置顶文章 + $all_results = array_merge($sticky_results, $non_sticky_results); + + // 内容分页 + $total_results = count($all_results); + $posts_per_page = 10; + $total_pages = ceil($total_results / $posts_per_page); + $current_page_results = array_slice($all_results, ($paged - 1) * $posts_per_page, $posts_per_page); + + //输出当前页内容 + if (!empty($current_page_results)) : + foreach ($current_page_results as $post) : + setup_postdata($post); + get_template_part('tpl/content', 'thumbcard'); + endforeach; + + //分页跳转 + the_posts_pagination(array( + 'total' => $total_pages, + 'current' => $paged, + )); + else : + //未找到搜索结果 + ?> + + + +