我已经创建了wordpress模板,它通过WP\\u查询对象使用两个循环。除了搜索小部件外,一切正常。三天来我一直在胡思乱想,现在像个疯子一样在谷歌上搜索,但没有找到解决办法。例如,在我的搜索框中,我键入:第一个cat(即“cat”类别中我的帖子的名称和内容),然后单击搜索,什么都不会发生。
奇怪的是:如果我在其他两个循环的上方创建一个“正常”(主循环),搜索小部件就会工作,但问题是,现在我的“正常”(主循环)会显示其他两个循环中的所有帖子
有人能帮我一下或给我一个建议如何解决这个问题吗
Link to my site 如果要检查我的非工作搜索小部件:(
Index.php)如下所示:
<?php get_header(); ?>
<?php get_sidebar(\'Main Sidebar\'); ?>
<div id="blogwrapper">
<div id="blog">
<?php if (have_posts()) : ?>
<?php
$paged1 = isset( $_GET[\'paged1\'] ) ? (int) $_GET[\'paged1\'] : 1;
$paged2 = isset( $_GET[\'paged2\'] ) ? (int) $_GET[\'paged2\'] : 1;
$args=array(
\'category_name\' => \'cats\',
\'paged\' => $paged1,
\'posts_per_page\' => 2,
\'order\' => \'DESC\'
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="post">
<div class="post_title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="entry">
<!--< ?php the_meta(); ?>-->
<?php the_post_thumbnail(); ?>
<?php the_content(\'Read on...\'); ?>
<p class="postmetadata">
<?php _e(\'Filed under:\'); ?> <br/><?php the_category(\', \') ?> <?php _e(\'by\'); ?> <?php the_author(); ?><br />
<?php comments_popup_link(\'No Comments »\', \'1 Comment »\', \'% Comments »\'); ?> <?php edit_post_link(\'Edit\', \' | \', \'\'); ?>
</p>
</div>
</div>
<?php endwhile;?>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn\'t here.</p>
<?php endif; ?>
<div class="navigation">
<?php
$pag_args1 = array(
\'format\' => \'?paged1=%#%\',
\'current\' => $paged1,
\'total\' => $wp_query->max_num_pages,
\'add_args\' => array( \'paged2\' => $paged2 )
);
echo paginate_links( $pag_args1 );
?>
</div>
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
</div><!--/blog-->
<div id="blogs">
<?php
$args2=array(
\'category_name\' => \'dogs\',
\'paged\' => $paged2,
\'posts_per_page\' => 2
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args2);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="post">
<div class="post_title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content(\'Read on...\'); ?>
<p class="postmetadata">
<?php _e(\'Filed under:\'); ?> <?php the_category(\', \') ?> <?php _e(\'by\'); ?> <?php the_author(); ?><br />
<?php comments_popup_link(\'No Comments »\', \'1 Comment »\', \'% Comments »\'); ?> <?php edit_post_link(\'Edit\', \' | \', \'\'); ?>
</p>
</div>
</div>
<?php endwhile;?>
<div class="navigation">
<?php
$pag_args2 = array(
\'format\' => \'?paged2=%#%\',
\'current\' => $paged2,
\'total\' => $wp_query->max_num_pages,
\'add_args\' => array( \'paged1\' => $paged1 )
);
echo paginate_links( $pag_args2 );
?>
</div>
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
</div>
</div><!--blogswrapper-->
<?php get_footer(); ?>
修改索引。php和主循环都可以运行(主循环显示其他两个循环中的所有帖子,但搜索小部件可以运行。)
<?php get_header(); ?>
<?php get_sidebar(\'Main Sidebar\'); ?>
<div id="blogwrapper">
<div id="blog">
//Now Search Widget is WORKING but its\'s showing posts from
//other TWO LOOPS so it looks like a BIG mess:(
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="post">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
<p class="postmetadata">
<?php _e(\'Filed under:\'); ?> <?php the_category(\', \') ?> <?php _e(\'by\'); ?> <?php the_author(); ?><br />
<?php comments_popup_link(\'No Comments »\', \'1 Comment »\', \'% Comments »\'); ?> <?php edit_post_link(\'Edit\', \' | \', \'\'); ?>
</p>
</div>
</div>
<?php endwhile; ?>
<div class="navigation">
<?php posts_nav_link(); ?>
</div>
<?php endif; ?>
</div>
<div id="blog">
<?php if (have_posts()) : ?>
<?php
$paged1 = isset( $_GET[\'paged1\'] ) ? (int) $_GET[\'paged1\'] : 1;
$paged2 = isset( $_GET[\'paged2\'] ) ? (int) $_GET[\'paged2\'] : 1;
$args=array(
\'category_name\' => \'cats\',
\'paged\' => $paged1,
\'posts_per_page\' => 2,
\'order\' => \'DESC\'
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="post">
<div class="post_title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="entry">
<!--< ?php the_meta(); ?>-->
<?php the_post_thumbnail(); ?>
<?php the_content(\'Read on...\'); ?>
<p class="postmetadata">
<?php _e(\'Filed under:\'); ?> <br/><?php the_category(\', \') ?> <?php _e(\'by\'); ?> <?php the_author(); ?><br />
<?php comments_popup_link(\'No Comments »\', \'1 Comment »\', \'% Comments »\'); ?> <?php edit_post_link(\'Edit\', \' | \', \'\'); ?>
</p>
</div>
</div>
<?php endwhile;?>
<?php else : ?>
<h2>Not Found</h2>
<p>Sorry, but you are looking for something that isn\'t here.</p>
<?php endif; ?>
<div class="navigation">
<?php
$pag_args1 = array(
\'format\' => \'?paged1=%#%\',
\'current\' => $paged1,
\'total\' => $wp_query->max_num_pages,
\'add_args\' => array( \'paged2\' => $paged2 )
);
echo paginate_links( $pag_args1 );
?>
</div>
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
</div><!--/blog-->
<div id="blogs">
<?php
$args2=array(
\'category_name\' => \'dogs\',
\'paged\' => $paged2,
\'posts_per_page\' => 2
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args2);
while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="post">
<div class="post_title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="entry">
<?php the_post_thumbnail(); ?>
<?php the_content(\'Read on...\'); ?>
<p class="postmetadata">
<?php _e(\'Filed under:\'); ?> <?php the_category(\', \') ?> <?php _e(\'by\'); ?> <?php the_author(); ?><br />
<?php comments_popup_link(\'No Comments »\', \'1 Comment »\', \'% Comments »\'); ?> <?php edit_post_link(\'Edit\', \' | \', \'\'); ?>
</p>
</div>
</div>
<?php endwhile;?>
<div class="navigation">
<?php
$pag_args2 = array(
\'format\' => \'?paged2=%#%\',
\'current\' => $paged2,
\'total\' => $wp_query->max_num_pages,
\'add_args\' => array( \'paged1\' => $paged1 )
);
echo paginate_links( $pag_args2 );
?>
</div>
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_postdata();
?>
</div>
</div><!--blogswrapper-->
<?php get_footer(); ?>