192 posts
  • Bought between 100 and 499 items
  • Has been a member for 5-6 years
  • United States
ace2296 says

I want the whole site to follow the same style sheet but I want one of my pages to look different than the rest… How do I go about accomplishing this? Thanks

4335 posts
  • Beta Tester
  • Bought between 10 and 49 items
  • Community Moderator
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Grew a moustache for the Envato Movember competition
+6 more
Reaper-Media Volunteer moderator says

Here’s how i’d go about it:

In your themes folder, wherever the stylesheet is defined, (most likely in the header.php file), use this:

<?php if( get_post_meta($post?>ID, 'style', true) == 'alternative' ){ ?>
    <link href="<?php bloginfo('template_directory'); ?>/alternative.css" rel="stylesheet" type="text/css" />
<?php } else { ?>
    <link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet" type="text/css" />
<?php }; ?>

Then in the page you want the stylesheet to be different, go to edit the page, and add a custom field at the bottom with a name of style and a value of alternative.

I haven’t checked the code thoroughly but it should work ;)

192 posts
  • Bought between 100 and 499 items
  • Has been a member for 5-6 years
  • United States
ace2296 says
Here’s how i’d go about it:

In your themes folder, wherever the stylesheet is defined, (most likely in the header.php file), use this:

<?php if( get_post_meta($post?>ID, 'style', true) == 'alternative' ){ ?>
    <link href="<?php bloginfo('template_directory'); ?>/alternative.css" rel="stylesheet" type="text/css" />
<?php } else { ?>
    <link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet" type="text/css" />
<?php }; ?>

Then in the page you want the stylesheet to be different, go to edit the page, and add a custom field at the bottom with a name of style and a value of alternative.

I haven’t checked the code thoroughly but it should work ;)

It didn’t work for me. It gave me a error on a line in the css

164 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 50 000 and 100 000 dollars
  • Won a Competition
tonyc says

<?php if( get_post_meta($post?>ID, ‘style’, true) == ‘alternative’ ){ ?>

Reaper made a small typo it should be $post->ID.

However I don’t think this is the best way to go about this. As this code does not make sense for the homepage for example.

You can try using is_single() or is_page() conditional tags if you know the id of the post you want to style differently

something like
if(is_single('id')){?>
  <link href="<?php bloginfo('template_directory'); ?>/alternative.css" rel="stylesheet" type="text/css" />
<?php }else{?>
  <link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet" type="text/css" />
<?php }?>
11 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 100 and 199 users
neel says

Hi you can simply achieve this by wordpress body_class() template tag which is added after wordpress 2.8

You can add this to body tag like

<body <?php body_class(); ?>>
which adds class to body tag and you can assign different styles per pages.

For more details check different styles for different pages

192 posts
  • Bought between 100 and 499 items
  • Has been a member for 5-6 years
  • United States
ace2296 says
Hi you can simply achieve this by wordpress body_class() template tag which is added after wordpress 2.8

You can add this to body tag like

<body <?php body_class(); ?>>
which adds class to body tag and you can assign different styles per pages. For more details check different styles for different pages

I’m sure your perfectly right its just this stuff is pretty confusing on where I need to implement the code and what custom fields I need for certain pages. Do you have a moment to fully explain this to me, if not I’m always on skype my user is ace2296. We could screen share on there so you can show me what to do for just chat live.

Thanks

1734 posts
  • Exclusive Author
  • Won a Competition
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Bought between 1 and 9 items
VisualSharing says
Reaper made a small typo it should be $post->ID.

It’s not exactly a typo, TF encodes -> as ?> in pre tags. If you click “Reply with quote” on his post, you’ll see the original post. :)

11 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 100 and 199 users
neel says
Hi you can simply achieve this by wordpress body_class() template tag which is added after wordpress 2.8

You can add this to body tag like

<body <?php body_class(); ?>>
which adds class to body tag and you can assign different styles per pages. For more details check different styles for different pages

I’m sure your perfectly right its just this stuff is pretty confusing on where I need to implement the code and what custom fields I need for certain pages. Do you have a moment to fully explain this to me, if not I’m always on skype my user is ace2296. We could screen share on there so you can show me what to do for just chat live.

Thanks

Well i added you on skype. my skype id is neel1015

192 posts
  • Bought between 100 and 499 items
  • Has been a member for 5-6 years
  • United States
ace2296 says
Hi you can simply achieve this by wordpress body_class() template tag which is added after wordpress 2.8

You can add this to body tag like

<body <?php body_class(); ?>>
which adds class to body tag and you can assign different styles per pages. For more details check different styles for different pages

I’m sure your perfectly right its just this stuff is pretty confusing on where I need to implement the code and what custom fields I need for certain pages. Do you have a moment to fully explain this to me, if not I’m always on skype my user is ace2296. We could screen share on there so you can show me what to do for just chat live.

Thanks
Well i added you on skype. my skype id is neel1015

Where’d you go?

192 posts
  • Bought between 100 and 499 items
  • Has been a member for 5-6 years
  • United States
ace2296 says
<?php if( get_post_meta($post?>ID, ‘style’, true) == ‘alternative’ ){ ?>

Reaper made a small typo it should be $post->ID.

However I don’t think this is the best way to go about this. As this code does not make sense for the homepage for example.

You can try using is_single() or is_page() conditional tags if you know the id of the post you want to style differently

something like
if(is_single('id')){?>
  <link href="<?php bloginfo('template_directory'); ?>/alternative.css" rel="stylesheet" type="text/css" />
<?php }else{?>
  <link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet" type="text/css" />
<?php }?>

Is there a custom field I need to put in the page that I’m assigning a different style sheet for this?

by
by
by
by
by
by