Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building a site which needs to have two search bars and two search results templates. One of the search bars is for regular posts, and the other is for a custom post type.

I need the two search results pages to be styled completely differently, so I have set up two templates to display results. One is the standard search.php that detects if the post type is a custom one, and displays it on a template named new-index.php

Im trying to attach different style sheets to the different pages using the following code:

<?php
if ( is_page_template('new-index.php')) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/home.css" />
<?php } ?>

which dosen't work, but if i use:

<?php
if ( is_search()) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/gallery.css" />
<?php } ?>

it works fine but it gives both the templates the same style sheet, I understand why its happening, but cannot figure out a way around it, any suggestions?

share|improve this question
add comment

1 Answer 1

I've never used is_page_template() but I have had good luck with is_page('new_search') regardless of which conditional you use some things to check.

Is the is_page_template('new-index.php') working. you may test this by doing something like:

if ( is_page_template('new-index.php')) { wp_die('new search page');}

You should also use wp_register_style and wp_enqueue_style in your functions.php hooking in the the wp_head which you should have better luck with.

share|improve this answer
    
is_page won't target it and the wp_die test didn't work! I haven't used wp_register_style before, I usually am able to link style sheets to different pages this way. is_search() is still the only one that affects it! –  RoseCoder Jun 27 '13 at 15:13
    
If the wp_die() didn't work then something is either wrong with the template name or how you are registering/displaying the custom search page. Could you provide more code or a link? Also your method works but wp_register_style is the more standard (WordPress) way to do it. –  BandonRandon Jun 27 '13 at 21:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.