search.php

Description: Displays a list of search results after a user has performed a search.

This template includes the following templates:

Template Code

<?php get_header(); ?>

	<div id="content" class="narrowcolumn">

	<?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 class="post">
				<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 include (TEMPLATEPATH . '/searchform.php'); ?>

	<?php endif; ?>

	</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

This template includes the following tags:

  • comments_popup_link() is a WordPress tag which displays a link either to the comments pop-up window or to the normal comments page, depending on which has been selected in the current template.
  • edit_post_link() is a Wordpress tag which displays a link to edit the current post (assuming the user is logged in and has the appropriate permissions).
  • get_footer() is a WordPress include tag which includes the file footer.php.
  • get_header() is a WordPress include tag which includes the file header.php.
  • get_sidebar() is a WordPress include tag which includes the file sidebar.php.
  • have_posts() is part of The Loop.
  • next_posts_link() is a WordPress tag. Counterintuitively, it creates a link to the previous posts.
  • previous_posts_link() is a WordPress tag. Despite its name, it creates a link to the next posts.
  • the_category() is a WordPress tag which displays a link to the category or categories that a post belongs to. This tag must be used within The Loop.
  • the_ID() is a WordPress tag which displays the numeric ID of the current post. This tag must be used within The Loop.
  • the_permalink() is a WordPress tag which displays the URL for the Permalink to the post currently being processed in The Loop. This tag must be used within The Loop.
  • the_post() is a WP_Query method: "Advance onto the next post, and set the global $post variable."
  • the_tags() is a WordPress tag which displays a link to the tag or tags a post belongs to. This tag should be used within The Loop..
  • the_time() is a WordPress tag which displays the time of the current post. This tag must be used within The Loop.
  • the_title() is a WordPress tag which displays or returns the title of the current post. This tag must be used within The Loop.
  • the_title_attribute() is a WordPress tag which displays or returns the title of the current post. This tag must be used within The Loop.

Other:

  • All the code between <?php if (have_posts()) : ?> and <?php endwhile; ?> constitutes The Loop.

HTML Skeleton

[HEADER.PHP]

<div id="content" class="narrowcolumn">

	<h2 class="pagetitle">Search Results</h2>

	<div class="navigation">
		<div class="alignleft">« Older Entries</div>
		<div class="alignright">Newer Entries »</div>
	</div>

	<div class="post">
		<h3 id="post-[#]">[POST TITLE]</h3>
		<small>[DATE]</small>
		<p class="postmetadata">
			Tags: [TAGS]<br/>
			Posted in [CATEGORIES] | [#] Comments »
		</p>
	</div>

	<div class="navigation">
		<div class="alignleft">« Older Entries</div>
		<div class="alignright">Newer Entries »</div>
	</div>

</div>

[SIDEBAR.PHP]

[FOOTER.PHP]

Related CSS Styles

Resources

  • N/A