198 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 500+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+10 more
Reaper-Media 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 ;)

198 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 500+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
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
  • Has been part of the Envato Community for over 5 years
  • Has referred 100+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
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

198 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 500+ items on Envato Market
  • Located in 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

1747 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
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
  • Has been part of the Envato Community for over 5 years
  • Has referred 100+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
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

198 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 500+ items on Envato Market
  • Located in 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?

198 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 500+ items on Envato Market
  • Located in 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?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by