Adding search to my website, please help!
-
I’m using an old theme and now need to add search to my website. It originally had no search.php or content-search.php which I have now added. Right now the results are pretty weird. I get the same result infinite times, and it says there’s nothing found yet gives the post.
Here is search.php:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title> <?php if ( is_single() ) { ?> <?php } ?><?php wp_title(':',true,right); ?> podliberty </title> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> <style type="text/css" media="screen"></style> <?php wp_head(); ?> </head> <body> <div class="wrapper"> <div class="header"> <div class="banner"> <a href="<?php echo home_url(); ?>"> <span class="logo"> <img src="https://podliberty.com/wp-content/themes/mnmlist/images/logo.png" alt="icon" /> </span> <span class="sitetitle">Podliberty</span> </a> </div> <div class="nav"> <a href="https://www.podliberty.com/about/">About</a> <span class="line">|</span> <a href="#">Become a contributor</a> </div> <div class="search"> <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/"> <div> <input placeholder="Search..." type="text" size="25" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" /> </div> </form> </div> </div> <div class="content"> <div class="bread"> <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } ?> </div> <div class="pagecontent"> <?php if (have_posts()) : ?> <?php // Start the loop. while ( have_posts() ) : the_post(); ?> <?php /* * Run the loop for the search to output the results. * If you want to overload this in a child theme then include a file * called content-search.php and that will be used instead. */ get_template_part( 'content', 'search' ); // End the loop. endwhile; // If no content, include the "No posts found" template. else : get_template_part( 'content', 'none' ); endif; ?> </div> <div class="sideboxes"> <div class="sidebox"> <?php $args = array( 'orderby' => 'ID', 'posts_per_page' => 5 ); $query = new WP_Query( $args ); ?> <h2>Latest Episodes</h2> <?php if ($query->have_posts()) : ?> <?php while ($query->have_posts()) : $query->the_post(); ?> <div class="postbox"> <div class="episodetitle" id="post-<?php the_ID(); ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </div> <div class="podcast"> <p> from <?php $categories = get_the_category(); $separator = ' '; $output = ''; if($categories){ foreach($categories as $category) { $output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "from %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator; } echo trim($output, $separator); } ?></p> </div> </div> <?php endwhile; ?> </div> <?php else : ?> <h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php endif; ?> <div class="sideboxtop"> <h2>Most Popular (24h)</h2> <?php wpp_get_mostpopular( 'stats_views=0&stats_category=1&limit=5&post_type=post' ); ?> </div> </div> </div> <div class="footer"> ? <?php echo date("Y"); ?> podliberty </div> </div> </body> </html>
And here is content-search.php:
<?php /** * The template part for displaying results in search pages. * * @package links */ ?> <div class="episodeblock"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="episode"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </div> <div class="episodeinfo"> <div class="thecategory"><?php $cat = get_the_category(); $cat = $cat[0]; ?> <a href="<?php echo get_category_link($cat);?>"><?php echo $cat->cat_name; ?></a> </div> <div class="thecontent"><?php the_content(); ?></div> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> </div> <?php links_paging();?> <?php else : ?> <h5><?php _e( 'Nothing Found', 'links' ); ?> for: <?php echo get_query_var('s');?>, maybe try some of these links?</h5> <?php $args = array( 'posts_per_page' => 7, 'orderby' => 'rand' ); ?> <?php $notfound = new WP_Query( $args );?> <?php while ( $notfound->have_posts() ) : $notfound->the_post() ?> <div class="post"> <div class="episode"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </div> <div class="episodeinfo"> <div class="thecategory"><?php $cat = get_the_category(); $cat = $cat[0]; ?> <a href="<?php echo get_category_link($cat);?>"><?php echo $cat->cat_name; ?></a> </div> <div class="thecontent"><?php the_content(); ?></div> </div> <p class="pull-right"><a href="<?php echo get_post_meta($post->ID, 'links_bookmark',true);?>"> <span class="glyphicon glyphicon-link"></span></a></p> </div> <?php endwhile; ?> <?php wp_reset_query(); ?> <?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Adding search to my website, please help!’ is closed to new replies.