Support » Plugins » Hacks » Search Template Control

  • danielkleindesign


    I created a custom theme for a corporate site I designed, and I’m having this issue with my Seach.php template file.

    The layout includes a column on the right that displays a list of links to featured posts, called via a tag I called “featured”. This list appears on the home page and on all level-1 pages, and I want it to remain intact on the Search Results page as well.

    Here’s the problem: Although the search is working like it should and is displaying the results inside the div I designated, it is also filtering out the featured links inside the right-hand column. So if the results do not include a word that is also present in the featured content, those links do not show up.

    Basically, I need to “protect” that part of the template, which is its own php file, from the search query.

    I am testing this locally, so the published site currently will not demonstrate the issue, but I am hoping there’s a code-smart individual out there who can examine this and help me find a solution.

    I have this snippet in my header.php file, which activates the search field:

    <div class="search">
            <?php $search_text = "Search"; ?>
    <form method="get" id="searchform"
    action="<?php bloginfo('home'); ?>/">
    <input type="text" value="<?php echo $search_text; ?>"
    name="s" id="s"
    onblur="if (this.value == '')
    {this.value = '<?php echo $search_text; ?>';}"
    onfocus="if (this.value == '<?php echo $search_text; ?>')
    {this.value = '';}" />
    <input type="hidden" id="searchsubmit" />

    And this is my search.php template:

    Template Name: search results
    <?php get_header(); ?>
        <div class="content_resize">
        <div class="mainbar">
          <div class="article">
          <h2>Search Results for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' : '); echo $count . ' '; _e('suggestions'); wp_reset_query(); ?></h2>
          <?php $posts=query_posts($query_string . '&posts_per_page=-1'); ?>
    	  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <a href="<?php the_permalink(); ?>">
    <div id="search_result">
    <div class="feature"><?php the_title(); the_excerpt(); ?></div>
    <?php endwhile; else: ?>
    	 <?php endif; ?>
    <?php include ('featbar.php'); ?>
    <?php get_footer(); ?>

    Finally, my featbar.php template that lists the links & excerpts for posts with the tag “featured”:

          <div class="column_right">
          <?php query_posts('tag=featured'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink(); ?>">
    <div class="feature_bar">
    <?php if (in_category('news-post')) { ?>
    <?php the_post_thumbnail(medium); ?>
    <div class="newsfeature"><feature_head><?php the_title(); ?></feature_head><div class="small_type"><?php the_excerpt(); ?></div>
    <?php }
    else { ?>
    <div class="feature_thumb">
    <?php the_post_thumbnail(thumbnail); ?></div>
    <div class="feature"><feature_head><?php the_title(); ?></feature_head><div class="small_type"><?php the_excerpt(); }?>
    <?php endwhile; ?>
          <div class="clr"></div>


Viewing 1 replies (of 1 total)
  • After further research I am realizing that this issue has something to do with the combination of the search query and the query_posts I have in the features bar. However I still don’t know what the solution might be.
    Here is a link to the site in case someone is willing to check it out and make a suggestion:

Viewing 1 replies (of 1 total)
  • The topic ‘Search Template Control’ is closed to new replies.