Forums

[resolved] Search Results and Read More together (8 posts)

  1. derrich
    Member
    Posted 5 years ago #

    Plain and simple...

    I want to incorporate the <!--more--> function or read more with the search results only. Therefore, when I search, I want the results to display the first 4 or 5 lines of the article and that's it.

    I found this, which didn't help me much in my cause...but helpful.
    http://codex.wordpress.org/Customizing_the_Read_More#Designing_the_More_Tag

    My blog:
    http://www.derrich.com/

  2. Kafkaesqui
    Moderator
    Posted 5 years ago #

    You could change the_content() template tag in your search template to the_excerpt(), which would do pretty much what you're after (display just the first several lines of your post).

  3. derrich
    Member
    Posted 5 years ago #

    Amazingly enough, I don't have that in my search.php file...

    [Moderated: edited out source (see Forum Rules, A.4), except for important part]

    <?php foreach ($posts as $post) : start_wp(); ?>
    <?php require('post.php'); ?>
    <?php endforeach; ?>

  4. Kafkaesqui
    Moderator
    Posted 5 years ago #

    <?php require('post.php'); ?>

    It's probably hiding in that file.

  5. Kafkaesqui
    Moderator
    Posted 5 years ago #

    Oh, and here's how you can get post.php to only display the_excerpt() in search results (but the_content() everywhere else):

    <?php if ( is_search() ) {
    the_excerpt();
    } else {
    the_content();
    } ?>

    More on conditional tags like is_search():

    http://codex.wordpress.org/Conditional_Tags

  6. derrich
    Member
    Posted 5 years ago #

    That worked...like a MF charm. Can I say MF here? =) Thank you! That's exactly what I wanted.

  7. Kafkaesqui
    Moderator
    Posted 5 years ago #

    "Can I say MF here?"

    That's the way we prefer it to be said. ;)

  8. derrich
    Member
    Posted 5 years ago #

    Shameless plug:
    For anyone else having this issue...or if you're curious...check out my blog and see this in action. Since I don't have many articles yet, search for "the" and you'll get the results in the format I'm talking about here.

    http://www.derrich.com/

Topic Closed

This topic has been closed to new replies.

About this Topic