Adding a search to custom theme
-
Hello WordPress!
I am in a little bit of a situation, I need to be able to add a working search bar to my custom theme.
The wordpress codex was not much help, most of the time I can get the search bar to show using the widget but it will not display any content it finds. I can not find anywhere to help set up a search.php or searchpage.php.
I am not sure if it would be a good idea to pull apart a wordpress made theme to get the search functionality out of it?
Any help would be a massive help,
Thanks
-
Hi guys,
So I have been going through the twenttyTifteen theme pulling out all of the search code.
So far i have the search bar displayed from the widgets, but once I type anything in it goes to another page saying
Search Results For: xxxxBut only if I have searched for something that is on the site, if I searched for something thats not on the site then the page is just blank.
I have so far
page.php
content-search.php
search.php
content.php
single.php
content-page.phpall from the theme into my own theme, but with no victory.
I have added this to the functions.php to make widgets work
function twentyfifteen_widgets_init() { register_sidebar( array( 'name' => __( 'Widget Area', 'twentyfifteen' ), 'id' => 'sidebar-1', 'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyfifteen' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h2 class="widget-title">', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'twentyfifteen_widgets_init' );I am unsure on if the functions.php needs anything else for the search to work?
Sorry for all these posts guys, trying to update as I go along. It is working much better now, just one issue with the single.php file
Once a user has searched for a word or phrase it spits out a list of the things it has found, like expected, but once a user clicks on the one they are looking for nothing is displayed other than the title
the fault is with the single.php but i am not sure why it is not displaying.
<?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <p>This is single.php</p> <h3><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></h3> <p><?php the_content(); ?></p> <hr> </main><!-- .site-main --> </div><!-- .content-area --> <?php get_footer(); ?>That is the single.php is but the_content(); is not showing up
The topic ‘Adding a search to custom theme’ is closed to new replies.