• 0

How to put a header on the Search Results page

Question

Posted · Report post

I know that if I do a search I can then edit the search results page. But I don't know how to provide it a header that automatically says something like "Search results for search on X". Seems like that's more user friendly and pretty common. But I'm not seeing how to do that.

 

I tried using the info on the relevant tutorial http://www.stemlegal.com/strategyblog/2011/improving-your-search-results-page/. I was able to add a text box with a heading and text HOWEVER I don't now how to add php code to a text box (if there IS a way) or if there's some other section I need to use. Surely I don't have to edit php templates, DO I?!

 

Using newest of everything. No url provided as this is a generic question for all my PL sites in DMS.

Thanks.

Share this post


Link to post
Share on other sites

19 answers to this question

  • 0

Posted · Report post

Hi Shelia

 

I used to use a plugin called http://wordpress.org/plugins/exec-php/ but that doesn't seem to have been updated in quiet a while. A good alternative might be http://wordpress.org/plugins/insert-php/.

 

Basically that will let you put the php in a textbox surrounded by a shortcode which will allow you to run the php on the page.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Thanks James. I actually already have that plug-in installed. I use it to put copyright years in my manually created footers.

 

So far I'm not figuring out how to create the functional shortcode. Can you tell me from the tutorial link what you you build in the shortcode?

 

OR...is there any other way... using just DMS to add this to search results? It seems like this should be a very basic thing already included?!

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

It is indeed a basic thing, add this to functions.php in your child theme:

 

https://gist.github.com/Pross/7928647

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Thanks Simon. That worked. I don't do much with that level of code. I'll play around with it some more. I can't see why the p tags are not making the  text match the rest of the p on the page. It's huge (20px). If you happen to see why that'd be helpful too. But this was already VERY helpful. Thanks.

 

just do a search (at end of nav bar) on my homepage http://www.hoffmangraphics.com to see.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hey Shelia, your site seems to be down at the moment.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

My  monitor says it hasn't been down. But what I just discovered is that using the www gives a scary message!

Warning: Cannot modify header information - headers already sent by (output started at /home/hoffman/public_html/wp-content/themes/viewer/functions.php:59) in /home/hoffman/public_html/wp-includes/pluggable.php on line 899

 

My site works fine without the www. Interesting.

 

I tested, given what it said, and reverted to the unedited functions.php and that error goes away. Any idea how to modify what I added from Simon so it works both with and w/o the www?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Where about do you mean can you provide a screenshot please.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Sorry Danny...do you mean where do I want this added? Or where did I add the code that caused the issue? I can do a shot if I'm clear what you want. But basically I want the top of every search page to have the standard message, something like: Search Results for the "search word here".... and then if there are no results it would say that and offer a search box. Right now search results come up with NOTHING at the top of the page. So I was trying to implement the instructions in the tutorial I included in my OP. Then I added the code Simon provided which worked for the first part. I added it to the child theme functions.php at the very bottom. Tell me what you want to see and I'll try to provide it.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

You have me confused now lol

 

Basically, you said the code Simon gave you worked, but you can't get the text to match something about p tags and 20pixels ?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

AH... So I'm attaching a capture of what it looks like with the edited functions.php. I'll leave it there for awhile. If you access the site with the www it will give you an error. But if you access it w/o typing www you can run a search and see what I mean. But unless we resolve the error issue I do not want to use it at all. I honestly can't believe there isn't a simple, built-in to DMS, way to accomplish this.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hmm, hehe still not sure what you mean.

 

I did a search with both www and without and didn't receive any error ?

 

I think I am misunderstanding you, If I am I apologise. :D

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

No you're not misunderstanding. When I do the search using www I get the error message previously listed. Not sure why. Could be specific to me / my hosting or computer. Don't know.

 

But since you can see it...what I'm saying is that the message the new code added is set between <p> tags yet the font size on the message is 20px where as the p style is set to 14px. So my question was why and how to fix that?

 

In addition I'm asking if there's a way to make this happen in DMS w/o manually editing the theme's functions.php? If not, I guess I should put it in as a suggested feature. Seems like an easy new section idea.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

if you paste the contents to paste.pagelines.com for functions.php i might be able to tell whats going on.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Sorry, got busy launching a new site today. Here's the url for the paste: http://paste.pagelines.com/fssYtbG7

It was the standard functions and I just added what Simon gave me to the bottom. I need to know why it only works w/o www and not with it or it's useless. Then if that's resolved I'd prefer to fix the typography. Thanks.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Hi Sheila

 

Looking through your source code the standard p tag is set to 20px.

 

It's overruled when the p tag appears inside the following classes to 14px .article-wrap .post-excerpt p, .article-wrap .entry_content p

 

http://screencast.com/t/UzYyOXZ6Mlsv

 

To fix it just add the following css

 

p {
    font-size: 14px;
    line-height: 1.55em;
}

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

THANK YOU! That fixed both issues. Now... I'd love to do more per the tutorial but don't quite know how to add these things correctly.

 

1) add this when no results... when there are no results, you can display:

<p>Your search for <?php the_search_query(); ?> has returned no results. Please double check your spelling, or try a new search below:</p>

 

2) Include the below code after the <?php endwhile; ?> portion of the loop, but before the <?php endif; ?>:

<p>Not finding what you were looking for? Try a new search below!</p>

<form class="clearfix" method="get" id="searchcontent" action="<?php bloginfo('home'); ?>/">
<input type="text" name="s" id="s" />
<button type="submit">Search</button>
</form>

 

Thanks!

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Well if there are no search results a searchbox is added there already.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Thanks, indeed there is! In fact it also says there are no results for X (search term). So good. I'm happy now. Thank you.

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now