Support » Themes and Templates » search.php edit to display more text

  • I’m using the wordpress default search.php page, but that only shows the post title and whether or not there are comments. I would like to display an excerpt of the posts-preferably the part that contains the search words.

    How do I go about doing this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Here’s the search page:

    <?php get_header(); ?>
    <div id="content" class="narrowcolumn">
    <?php if (have_posts()) : ?>
         <h3 class="pagetitle">Search Results</h3>
             <div class="navigation">
    	    <div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
                <div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    <?php while (have_posts()) : the_post(); ?>
         <div class="post">
    	<h4 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h4>
    	<small><?php the_time('l, F jS, Y') ?></small>
            <p class="postmetadata">Posted in <?php the_category(', ') ?> |
            <?php edit_post_link('Edit', '', ' | '); ?>
            <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    <?php endwhile; ?>
         <div class="navigation">
    	<div class="alignleft">
               <?php next_posts_link('&laquo; Previous Entries') ?>
            <div class="alignright">
               <?php previous_posts_link('Next Entries &raquo;') ?>
    <?php else : ?>
        <h3 class="center">No posts found. Try a different search?</h3>
        <p>&nbsp;</p><center><?php include (TEMPLATEPATH . '/searchform.php'); ?></center>
    <?php endif; ?>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Check out template tags. Under “Post tags,” look at the_content() and (especially) the_excerpt().

    If you want it to display the text around the search term, that isn’t a built-in feature to my knowledge, though you could do it yourself in an hour or two if you are handy with PHP.

    Thanks for the help!

    any help on displaying both post title and excerpt?

    What more help do you need besides going to read the Codex page that adam suggested above?

    Charissaproctor, the codex might seem intimidating, but it’s actually easier to follow than you’d expect.

    Basically, after this line: <small><?php the_time('l, F jS, Y') ?></small> use either <?php the_excerpt(); ?> or <?php the_content('Read more...'); ?> to display your text.

    thank you…that was helpful….does anyone know how to possibly show the full post and title on the search results page and how to adjust the h2 class of the title for search results to match the post title for the main page?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘search.php edit to display more text’ is closed to new replies.