• I have created a page specifically for searching purposes. And the return result is to show the title together with the date posted. My problem is when i go to the search page without searching for anything, it will show me the title and date of the page itself. For example:

    SEARCH (Title)
    8th October 2007 (Date)

    How do i make this disappear?

Viewing 8 replies - 1 through 8 (of 8 total)
  • when you say you’ve created a “page” do you mean a WordPress page? or a search.php for your theme?

    If you mean the former, then I suggest you look into the latter.

    Thread Starter reneechung

    (@reneechung)

    a search.php for my theme.

    well then the code is somewhere in that php file…

    if you want to hide the heading when there are no results, make sure you do something like:

    <?php if (have_posts()) : ?>
    
    (everything here, like headings, is displayed
    only if there are posts)
    
    (the loop goes here, for all your search results)
    
    (everything you want AFTER the loop goes outside
    of it, but still inside these tags, if you want
    it hidden when there are no posts!)
    
    <?php else : ?>
    
    (alternate HTML to display when there are no results!)
    
    <?php endif; ?>
    Thread Starter reneechung

    (@reneechung)

    this is how my code looks like

    Thread Starter reneechung

    (@reneechung)

    <?php if (have_posts()) : ?>
    				<ul class="line">
    					<?php while (have_posts()) : the_post(); ?>
    					<li>
    						<p class="post-title">
    							<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a><br />
    							<span class="post-small">
    								<?php the_date();?><br />
    								FILED UNDER <?php the_category(', ') ?>
    							</span>
    						</p>
    					</li>
    					<?php endwhile; ?>
    				</ul>
    				<?php else : ?>
    					<p>No posts found. Try a different search?</p>
    				<?php endif; ?>

    that’s the whole file? – nothing before the <?php if (have_posts()) : ?> ?

    If that’s the case, then I don’t know why you’re getting a heading on the page that says “SEARCH”

    … unless I’m not understanding correctly, and you’re telling me this is the page TITLE, like in the header maybe. If that’s the case, then perhaps a plugin is adding that.

    Thread Starter reneechung

    (@reneechung)

    Oh yes there are other codes before that. Sorry let me post it up properly.

    <?php
    /*
    Template Name: Find
    */
    ?>
    <?php get_header();?>
    	<div id="content" class="w1260">
    		<?php get_sidebar();?>
    		 <div class="column">
    		 	<h1>SEARCH</h1>
    			<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    		 </div>
    		 <div class="column2 last">
    		 	<div id="scroller2">
    				<?php if (have_posts()) : ?>
    				<ul class="line">
    					<?php while (have_posts()) : the_post(); ?>
    					<li>
    						<p class="post-title">
    							<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a><br />
    							<span class="post-small">
    								<?php the_date();?><br />
    								FILED UNDER <?php the_category(', ') ?>
    							</span>
    						</p>
    					</li>
    					<?php endwhile; ?>
    				</ul>
    				<?php else : ?>
    					<p>No posts found. Try a different search?</p>
    				<?php endif; ?>
    			</div>
    		 </div>
    	</div>
    <?php get_footer();?>

    I can see by what you’ve pasted that your question is answered, you just need to re-read my second post.

    That If/else/endif controls what’s seen when there are search results, and when there are none.

    You just need to position your elements around that so that the correct stuff is displayed.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Search Results’ is closed to new replies.