我有一个WordPress Multisite,想要显示来自家庭网站上所有子站点的博客类别的搜索结果。
这是search.php文件代码。我可以切换博客以显示结果,但希望合并子网站的所有搜索。
<?php
/**
* The template for displaying Search Results pages
*
* @package WordPress
* @subpackage xsite
* @since xsite 1.0
*/
get_header(); ?>
<div class="SearchBlue">
<div class="container">
<div class="row">
<div class="col-md-12"><h1>Search Results</h1></div>
</div>
<div class="row">
<div class="col-md-11 col-sm-11 col-xs-11">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("s=$s&paged=$paged&cat=2"); ?>
<?php $searchString = get_search_query(); ?>
<input type="text" class="form-control" id="searchInputStatic" placeholder="<?= $searchString ?>">
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<a id="searchSubmitStatic" class="btn btn-primary" title="search" href="#">Go</a>
</div>
</div>
<br />
<div class="row">
<div class="col-md-12">
<?php
global $wp_query;
if ($wp_query->found_posts > 0) {
?>
<p class="resultsCount"><?= $wp_query->found_posts ?> results found.</p>
<?php } else { ?>
<p class="resultsCount">Sorry, no results were found. Please try again.</p>
<?php } ?>
</div>
</div>
</div><!-- container -->
</div><!-- SearchBlue -->
<div class="clearfix"></div>
<?php if (have_posts()) : ?>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("s=$s&paged=$paged&cat=2"); ?>
<div class="container" id="searchResultsContent">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<?php $searchString = get_search_query(); ?>
<?php while (have_posts()) : the_post(); ?>
<?php
get_template_part('content', get_post_format());
?>
<?php endwhile; ?>
</div>
</div><!-- row -->
</div><!-- container -->
<?php endif; ?>
<?php get_footer(); ?>