Forums

Help with search (14 posts)

  1. jgurley
    Member
    Posted 6 years ago #

    I recently upgraded to the current version of WP. Instead of using one of the default themes, I ported my existing site into a custom theme.

    I would like to add search functionality to my site, but frankly, don't have a clue where to begin. Can somebody point me to a simple tutorial, or give me some idea of how to start?

  2. moshu
    Member
    Posted 6 years ago #

    The best bet is to look at the two themes (Classic and Default) that come with the standard WP package... and "steal" from there how did they do it :)

  3. jgurley
    Member
    Posted 6 years ago #

    Actually, I did that. I just get lost when I'm looking at PHP that I don't understand (I'm far from comfortable with PHP, to be honest).

  4. moshu
    Member
    Posted 6 years ago #

    Default has a separate file called searchform.php and it is called with 1 (one) line of code.
    Classic has it in the sidebar and probably it starts with something like: <form...

    No PHP involved, it's basic html
    http://www.w3schools.com/html/html_forms.asp

  5. jgurley
    Member
    Posted 6 years ago #

    I'll give it a fresh look, thank for the help.

  6. jgurley
    Member
    Posted 6 years ago #

    Moshu, I've stripped the <form> out of the Default template and plugged it into my site (www.deeplyshallow.com, see the left sidebar, beneath all sidebar content) to test it.

    The form works, but it doesn't return actual results... instead, it returns the most recent entry that contains that term.

    How do I modify it to return actual results instead of a full entry?

  7. moshu
    Member
    Posted 6 years ago #

    I assume you have set your blog to show 1 post on main page AND you don't have the post_nav_link to navigate to earlier posts.

    You may want to consider creating a search.php template file >> see Template_Hierarchy

    EDIT. And of course, you'llhave to find a way to change the number of posts displayed on that page, e.g. with one of these plugins:
    http://mattread.com/archives/2005/03/custom-query-string-plugin/
    http://rephrase.net/miscellany/05/perpage.phps

  8. jgurley
    Member
    Posted 6 years ago #

    Blog's set to show 1 post on the page, yes. And I use the previous_post/next_post links to get to earlier/newer posts.

    Is it possible to just display a results page with a list of links to posts, instead of the actual posts? Making someone search and then presenting them with an inordinately long page of multiple posts, with no easy way of choosing which one is what they're looking for, seems like more trouble than it's worth. (For the reader, I mean.)

  9. moshu
    Member
    Posted 6 years ago #

    Is it possible to just display a results page...
    That's exactly what showed above. In that template it is up to you whether you display the whole post, the excerpt or only the title.

  10. jgurley
    Member
    Posted 6 years ago #

    Okay, sweet! One last thing: is there a guide anywhere for creating a search.php template? Anything to help me with the process?

    Thanks very much for your help/patience.

  11. moshu
    Member
    Posted 6 years ago #

    Save your index.php (or better the archive.php - if you have one) as search.php and play with the template tags: Template_Tags.
    In general about template files in a WP theme, see Templates

  12. jgurley
    Member
    Posted 6 years ago #

    I have an archive.php, but it uses Shawn Grimes's Clean Archives plug-in -- in that case would it be better to use the index.php as the basis instead?

  13. moshu
    Member
    Posted 6 years ago #

    Nope, that's not a template file as I see it. Use the index.

  14. jgurley
    Member
    Posted 6 years ago #

    Great. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags