admin管理员组文章数量:1130349
right now i have a problem in the search result page (search.php) the result is shown by the index page template not its template and it display all the posts despite it have what the searcher enter or not
my index.php page
<?php get_header(); ?>
<?php
$search = $_get['search'];
$args = array(
'post_title_like' => $search
);
$res = new wp_query($args);
if ($res -> have_posts()){
while ($res -> have_posts()) {
$res -> the_post();
?>
<!--start section 1-->
<section class="section1" style="margin: 0;box-shadow: 0 2px 10px">
<div class="container">
<a href="<?php echo get_post_permalink(); ?>">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
</a>
<div class="clearfix"></div>
</div>
</section>
<!--end section 1-->
<?php the_content(); ?>
<?php
}
}
?>
<?php get_footer() ?>
my search.php page
<?php get_header(); ?>
<?php
if (have_posts()){
while (have_posts()) {
the_post();
?>
<section class="section1" rule="main">
<div class="container">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
<div class="clearfix"></div>
</div>
</section>
<?php
}
}
?>
<?php get_footer(); ?>
if you need more code please tell me
right now i have a problem in the search result page (search.php) the result is shown by the index page template not its template and it display all the posts despite it have what the searcher enter or not
my index.php page
<?php get_header(); ?>
<?php
$search = $_get['search'];
$args = array(
'post_title_like' => $search
);
$res = new wp_query($args);
if ($res -> have_posts()){
while ($res -> have_posts()) {
$res -> the_post();
?>
<!--start section 1-->
<section class="section1" style="margin: 0;box-shadow: 0 2px 10px">
<div class="container">
<a href="<?php echo get_post_permalink(); ?>">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
</a>
<div class="clearfix"></div>
</div>
</section>
<!--end section 1-->
<?php the_content(); ?>
<?php
}
}
?>
<?php get_footer() ?>
my search.php page
<?php get_header(); ?>
<?php
if (have_posts()){
while (have_posts()) {
the_post();
?>
<section class="section1" rule="main">
<div class="container">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
<div class="clearfix"></div>
</div>
</section>
<?php
}
}
?>
<?php get_footer(); ?>
if you need more code please tell me
Share Improve this question asked Nov 23, 2018 at 11:36 abdo sayedabdo sayed 31 bronze badge1 Answer
Reset to default 0The search.php template is used, and the correct posts returned, when a search is performed with the ?s= query. Not ?search=. Make sure the name attribute of the input in your search form is s:
<input type="search" name="s">
And your index.php file should absolutely not be using a custom query like that. Use the main loop the same way you have in search.php. WordPress already queries the correct posts for you.
if ( have_posts() ){
while ( have_posts() ) {
the_post();
}
}
right now i have a problem in the search result page (search.php) the result is shown by the index page template not its template and it display all the posts despite it have what the searcher enter or not
my index.php page
<?php get_header(); ?>
<?php
$search = $_get['search'];
$args = array(
'post_title_like' => $search
);
$res = new wp_query($args);
if ($res -> have_posts()){
while ($res -> have_posts()) {
$res -> the_post();
?>
<!--start section 1-->
<section class="section1" style="margin: 0;box-shadow: 0 2px 10px">
<div class="container">
<a href="<?php echo get_post_permalink(); ?>">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
</a>
<div class="clearfix"></div>
</div>
</section>
<!--end section 1-->
<?php the_content(); ?>
<?php
}
}
?>
<?php get_footer() ?>
my search.php page
<?php get_header(); ?>
<?php
if (have_posts()){
while (have_posts()) {
the_post();
?>
<section class="section1" rule="main">
<div class="container">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
<div class="clearfix"></div>
</div>
</section>
<?php
}
}
?>
<?php get_footer(); ?>
if you need more code please tell me
right now i have a problem in the search result page (search.php) the result is shown by the index page template not its template and it display all the posts despite it have what the searcher enter or not
my index.php page
<?php get_header(); ?>
<?php
$search = $_get['search'];
$args = array(
'post_title_like' => $search
);
$res = new wp_query($args);
if ($res -> have_posts()){
while ($res -> have_posts()) {
$res -> the_post();
?>
<!--start section 1-->
<section class="section1" style="margin: 0;box-shadow: 0 2px 10px">
<div class="container">
<a href="<?php echo get_post_permalink(); ?>">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
</a>
<div class="clearfix"></div>
</div>
</section>
<!--end section 1-->
<?php the_content(); ?>
<?php
}
}
?>
<?php get_footer() ?>
my search.php page
<?php get_header(); ?>
<?php
if (have_posts()){
while (have_posts()) {
the_post();
?>
<section class="section1" rule="main">
<div class="container">
<div class="img">
<?php the_post_thumbnail(); ?>
</div>
<h1 class="page-title"><?php the_title(); ?></h1>
<div class="clearfix"></div>
</div>
</section>
<?php
}
}
?>
<?php get_footer(); ?>
if you need more code please tell me
Share Improve this question asked Nov 23, 2018 at 11:36 abdo sayedabdo sayed 31 bronze badge1 Answer
Reset to default 0The search.php template is used, and the correct posts returned, when a search is performed with the ?s= query. Not ?search=. Make sure the name attribute of the input in your search form is s:
<input type="search" name="s">
And your index.php file should absolutely not be using a custom query like that. Use the main loop the same way you have in search.php. WordPress already queries the correct posts for you.
if ( have_posts() ){
while ( have_posts() ) {
the_post();
}
}
本文标签: search results in custom template searchphp
版权声明:本文标题:search results in custom template search.php 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749157246a2324803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论