Community Forums › Forums › Archived Forums › General Discussion › Displaying only post titles in search results
- This topic has 5 replies, 2 voices, and was last updated 10 years, 11 months ago by
David Chu.
-
AuthorPosts
-
April 3, 2014 at 8:47 am #98289
pixelhappy
MemberHello.
I saw a handful of posts asking this same question here in the forums but never really found an answer.
Which is why I am posting this question again.
Would love to be able to display only post titles on search results and after Google ing for a few hours, I'm still not sure how to do this.
Any ideas would be appreciated!
Thanks, Yael
Web developer. WordPress and Genesis Junkie. Yoga lover and aspiring peace maker.
April 3, 2014 at 10:14 am #98301David Chu
ParticipantHi Yael,
I found that to be an interesting question. WP search, as you probably found in your Googling, is funky. 🙂The general thing you need to do is to make a search.php file in your child theme. This will override the stock WP results. Here is an example of code that you can try. It's pretty generic and easy to follow. As you can see, it just uses the title and the link, no "content" or other bits.
Take the following code, save it as a file named search.php, and then upload it to your child theme's folder. I tested it, and it works great.
<?php /** * Search Results Template File */ get_header(); ?> <header> <h1>Search Results: "<?php echo get_search_query(); ?>"</h1> <br> </header> <?php if ( have_posts() ) : // results found?> <?php while ( have_posts() ) : the_post(); ?> <article> <p> <a href=""<?php">"><?php the_title(); ?></a> </p> </article> <?php endwhile; ?> <?php else : // no results?> <article> <h1>No Results Found.</h1> </article> <?php endif; ?> <?php get_footer(); ?>
Cheers, Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
April 3, 2014 at 11:43 pm #98400pixelhappy
MemberThanks for this Dave. When I try this, though, I get an error message on the search results page:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/kitche11/public_html/wp-content/themes/dynamik-gen/search.php on line 19
Wonder why it works for you and not me ? I"ll double check the code I added and see if I somehow copied over incorrectly.
Thanks for helping out here.
Yael
Web developer. WordPress and Genesis Junkie. Yoga lover and aspiring peace maker.
April 4, 2014 at 7:42 am #98435David Chu
ParticipantYael,
Glad to help.Ah, I think I see what happened. You did nothing wrong, and even though you're apparently using Dynamik, I think this method should still work. btw, this is a regular WordPress method, not a Genesis-specific procedure.
This forum software butchers code, even when you use the tags they tell you to use. Pop over here and try that code instead. 🙂
Cheers, Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
April 4, 2014 at 7:53 am #98439pixelhappy
MemberWahoo, thank you Dave! I so appreciate your help -- works like a charm :0
Web developer. WordPress and Genesis Junkie. Yoga lover and aspiring peace maker.
April 4, 2014 at 8:02 am #98441David Chu
ParticipantSuper! Good to meet you.
Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.