WordPress.org

Ready to get started?Download WordPress

Forums

How do you display the search term that was used above the results (7 posts)

  1. Matthew Kinneman
    Member
    Posted 10 months ago #

    I set up a google custom search in our website and want the search term to display above the results.

    How do you display the search term above the results, example RESULTS FOR: (word that was typed in the search box). Basically I'm trying to set the search results on this page: https://vitaminsforpitbulls.com/search/?query=bully%20max

    to look like this page where is shows the term you searched for:
    http://yoast.com/search/?q=seo&cx=006835583451239722573%3Av_p3wvnlqke&num=25&cof=FORID%3A9

  2. alchymyth
    The Sweeper & Moderator
    Posted 10 months ago #

    untested if this works with google search;
    http://codex.wordpress.org/Template_Tags/get_search_query

  3. Matthew Kinneman
    Member
    Posted 10 months ago #

    I was reading around and someone with the same issue used the following code:<h1 class="page-title"><?php echo( 'Search Results for: "'); ?><span><?php echo $_GET['q']; ?></span>"</h1> However, I tried to enter it into the search page with no luck. Where do these codes need to be entered? Here is the current code for the search results page:

    <?php get_header(); ?><h1 class="page-title"><?php echo( 'Search Results for: "'); ?><span><?php echo $_GET['q']; ?></span>"</h1>
    <div id="contentarea" class="row">
    	<?php if (get_option(SHORTNAME . '_post_listing_layout') == 'left')
    	{ ?>
    		<aside class="grid_3 left-sidebar">
    			<?php (get_option(SHORTNAME . '_post_listing_sidebar')) ? $sidebar = get_option(SHORTNAME . '_post_listing_sidebar') : $sidebar = "default-sidebar";
    			generated_dynamic_sidebar_th($sidebar);
    			?>
    		</aside>
    		<?php } ?>
    	<div class="<?php echo (get_option(SHORTNAME . '_post_listing_layout') == 'none') ? 'grid_12' : 'grid_9'; ?>">    
    
    <?php if (have_posts()) : ?>
    <script>
      (function() {
        var cx = '008150889077634852566:korkzx0njc8';
        var gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
            '//www.google.com/cse/cse.js?cx=' + cx;
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
      })();
    </script>
    <gcse:searchresults-only></gcse:searchresults-only>
    		<?php endif; ?>
    	</div>
    	<?php if (get_option(SHORTNAME . '_post_listing_layout') == 'right')
    	{ ?>
    		<aside class="grid_3 right-sidebar">
    	<?php (get_option(SHORTNAME . '_post_listing_sidebar')) ? $sidebar = get_option(SHORTNAME . '_post_listing_sidebar') : $sidebar = "default-sidebar";
    	generated_dynamic_sidebar_th($sidebar);
    	?>
    		</aside>
    <?php } ?>
    <div class="clear"></div>
    </div>
    <?php get_footer(); ?>
  4. Evan Herman
    Member
    Posted 10 months ago #

    When I run a search on your page I get an 'error establishing connection with database' error.

  5. Matthew Kinneman
    Member
    Posted 10 months ago #

    Evan, I just took care of that issue. Thanks

  6. Christian1012
    Member
    Posted 10 months ago #

    <?php echo $_GET['query']; ?>

    If the search term was "Hello World", this would would print Hello World to the browser. You can put this where you want it, but the code you tried to copy/paste would insert another h1 tag, and you only want one of them per page.

  7. Matthew Kinneman
    Member
    Posted 10 months ago #

    The 'error establishing connection with database' issue that is. I'm still having trouble getting the results to show the search term

Reply

You must log in to post.

About this Topic