WordPress.org

Ready to get started?Download WordPress

Forums

search.php edit to display more text (8 posts)

  1. itissue
    Member
    Posted 6 years ago #

    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?

  2. itissue
    Member
    Posted 6 years ago #

    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>
             </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>
         </div>
    <?php endwhile; ?>
         <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>
          </div>
    <?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; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  3. Adam Brown
    Member
    Posted 6 years ago #

    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.

  4. itissue
    Member
    Posted 6 years ago #

    Thanks for the help!

  5. charissaproctor
    Member
    Posted 6 years ago #

    any help on displaying both post title and excerpt?

  6. moshu
    Member
    Posted 6 years ago #

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

  7. thecoup
    Member
    Posted 6 years ago #

    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.

  8. charissaproctor
    Member
    Posted 6 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags