Trouble with search results
-
I’m creating a custom theme for my WordPress site and I’m having trouble display search results in my blog pages. The search query submits just fine, if I echo the get_query_var( ‘s’ ) the correct query is displayed. The URL attributes looks fine as well (?s=7+Ways+to+Maximize&x=0&y=0), apparently the x & y are appended if your submit button is type image. The problem is stemming from my use of query_posts() in my loop, which I’m using to eliminate a category from being displayed within the blog. I’ve figured out how to fix the query to work with archives, authors, pages, but I can’t figure out how to get it to now work with the search functionality. I’ve looked around here on the forum some but no luck thus far. Can anyone point me in the right direction or give me some tips?
My development site is located here.
My Loop:
<ul id="posts"> <?php echo get_query_var( 's' ); $temp_query = $wp_query; $category = ( get_query_var( 'cat' ) ) ? get_query_var( 'cat' ) : -17; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $author = ( get_query_var( 'author' ) ) ? get_query_var( 'author' ) : NULL; $month = ( get_query_var( 'monthnum' ) ) ? get_query_var( 'monthnum' ) : NULL; $year = ( get_query_var( 'year' ) ) ? get_query_var( 'year' ) : NULL; // default category (all posts) returns as -0, if this is the case set it to -17 to ignore the 'news' category if ( $category == -0 ) $category = -17; $query_string = 'cat=' . $category . '&paged=' . $paged; if ( $year != NULL && $month != NULL ) $query_string .= '&year=' . $year . '&monthnum=' . $month . '$&order=DSC'; if ( $author != NULL ) $query_string .= '&author=' . $author; //echo $query_string; query_posts( $query_string ); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li id="post-<?php the_ID(); ?>" class="clear"> <div class="author"> <img src="<?php bloginfo('template_directory') ?>/images/authors/<?php the_author_ID()?>.jpg" alt="<?php the_author(); ?>" width="86" height="94" /> <?php the_author_posts_link( null,'mar_10_b'); ?> </div> <div class="preview"> <p class="date orange_14px"><?php the_time('F j, Y'); ?></p> <h2 class="red_18px"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <p><?php the_excerpt(); ?></p> <div class="clear"> <a href="<?php the_permalink() ?>" title="Read More">Read More »</a> <a href="#" title="Share This Post" class="share">Share</a> <a href="<?php the_permalink() ?>#view_comments" title="View Comments" class="comments"><?php comments_number('No Comments', '1 Comment', '% Comments' );?></a> </div> </div> </li> <li class="rule"></li> <?php endwhile; ?> <li class="pagination clear"> <?php next_posts_link('Previous Entries »', 0, 'prev') ?> <?php previous_posts_link('« Newer Entries', 0, 'next') ?> </li> </ul> <?php endif; ?>
The topic ‘Trouble with search results’ is closed to new replies.