Using different style sheets for different templates
June 3, 2007 – 8:24 am | by Miriam SchwabI’m creating a site where the pages are divided into two sections: Hebrew and English. I need the Hebrew pages to use a template that basically looks the same as the English pages, but everything is switched around to right-to-left.
I created a copy of the style sheet and called it style-hebrew.css. In the copy, I made all the relevant changes so that everything is flipped around, which basically meant writing direction: rtl in a bunch of places, and floating things to the right instead of left, and vice versa. But now I needed a way to call this style sheet on the Hebrew pages.
First, I created a page template called hebrew-page.php. In this template, I replaced
<?php get_header(); ?>
with
<?php include ('header-hebrew.php'); ?>
Then I copied the header.php file and renamed it header-hebrew.php. In this file, I replaced the usual call to the style sheet:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
with the call to my new Hebrew style sheet:
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/style-hebrew.css" type="text/css" media="screen" />
Now, in the admin, whenever a Hebrew page is created, they just have to make sure to select the Hebrew Page template from the Page Template drop-down menu on the right-hand panel.
This method can be used for any site that needs to call different styles for different pages or categories. Just create another style sheet and header.php files, and call them in the appropriate places.
There may be a more efficient way to do this, but I have yet to discover it.



4 Responses to “Using different style sheets for different templates”
By PB on Apr 7, 2008 | Reply
Great job! Simple…and it works. I wanted to call a different header on some custom pages and googling for a solution returned nothing but complex instructions and php hacks that did not apply. Glad I found this.
By René Kragh Pedersen on Aug 8, 2008 | Reply
Short, to the point, and it works.
Thank you very much.
By Andrew on Aug 23, 2008 | Reply
You rock, thanks for the tip. Works great. Thanks once more.
By daniel on Sep 3, 2008 | Reply
can you tell me how to convert templates into hebrew ones?
direction: rtl; not always work
and the menues are still left to right
thanks