Different Searchform for Each Category
-
I have set up different sidebars per category to allow for search within each category. The link to the searchform is
<form name="searchform" id="searchform" method="get" action="<?php bloginfo('url'); ?>/topic/news/#content">
This returns search results for the category ‘news’ (I’ve set my category base to ‘topic’)
I’ve created separate search results pages for each category. For example, search-news.php is the search results page for news category.
My search.php is
<?php if ( have_posts() ) { the_post(); rewind_posts(); } if ( in_category(55) ) { include(TEMPLATEPATH . '/search-art.php'); // Sends search for articles to different search page } if ( in_category(3) ) { include(TEMPLATEPATH . '/search-news.php'); // Sends search for news to different search page } else { include(TEMPLATEPATH . '/search-blog.php'); // Defaults to search page for blog } ?>
All this works fine. Where it hangs is if the search query returns nothing. Then, the searchform that gets called up in the search results page is ALWAYS the default blog searchform. The part after the
<?php else : ?> below doesn’t seem to be working. Can anyone tell me where I am going wrong?<?php if (have_posts()) : ?> <h1 class="pagetitle"><?php _e('Search Results for '); ?><?php the_search_query(); ?></h1> <?php while (have_posts()) : the_post(); ?> <div class="post"> <h2 class="posttitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent Link to'); the_title(); ?>"><?php the_title(); ?></a></h2> <?php endif; ?> </div> <?php endwhile; ?> </div> <?php else : ?> <h1 class="pagetitle"><?php _e('No posts found. Try a different search?') ?></h1> <?php include (TEMPLATEPATH . '/searchform-news.php'); ?> <?php endif; ?>
- The topic ‘Different Searchform for Each Category’ is closed to new replies.