I have created a searchfrom.php for wordpress but then it’s giving me a false returns you can try the search yourself here
Here is the code for my search form
<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" class="form-text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" class="goField" />
</form>
Here is the code of my search.php page
get_header(); ?>
<div id="BodyWrap">
<div id="mainCont">
<?php get_sidebar(); ?>
<div id="mainCopy">
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : ?>
<h2 class="pagetitle">Search Results</h2>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2 class="center">No posts found. Try a different search?</h2>
<?php get_search_form(); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
It does do the search but there are this “at | Uncategorized | No comment” which is not even part of the search term.
Oh, I see. You want to know why it lists categories even if they don’t match the search term?
Well, that’s the default WordPress behavior. I guess you could change it, but I don’t see why, actually.
It is the
part in your search.php that displays the categories and comments count. However, if you remove the code above, the categories and comments count will not be shown (even if the categories matches your search term).
You may replace the code above with this code, if you only want to display the categories if they are the same as the search term:
It should produce something like this, if the categories match the search term:
If the categories don’t match the term:
If you don’t want the comments count (or Comments Off) to display, remove the
comments_popup_link('No Comments »', '1 Comment »', '% Comments »');
line from my code.You’ll have to edit your page.php or single.php to exclude the search page from showing the Comments/Categories.
Maybe change searchform.php to this?
Remove the line that’s wrapped in
. That will get rid of the “Posted in Uncategorized | Comments Off”.
The reason it show’s is because it is the meta information for your search result. It will be displayed in your results even if it wasn’t the search term because it is associated with it.
All in all, your search.php page should look like this: