osCommerce Community Support Forums: Multiple Stylesheets - osCommerce Community Support Forums

Jump to content

Corporate Sponsor


Tips and Tricks Guidelines

Tips and tricks are only allowed to be posted in this forum channel. For support, please post in another related channel in this forum. If you come across a post not related to a tip or trick, please report it so it can be deleted.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Multiple Stylesheets An easy way to include additional stylesheets. Rate Topic: -----

#1 User is offline   Skittles Icon

  • Find Posts
  • Group: Community Member
  • Posts: 335
  • Joined: 02-March 06
  • Real Name:Anita L. Cross
  • Gender:Female
  • Location:Oregon

Posted 17 August 2006 - 12:08 AM

I'm in the process of converting my website from a "homemade" javascript cart to osCommerce. This site uses CSS layout, and it is necessary to have all the osCommerce pages use my existing stylesheets.

I started out adding the link tag in the html header:

<link rel="stylesheet" type="text/css" href="stylesheet.css">
 <link rel="stylesheet" type="text/css" href="../support/mystylesheet1.css">
 <link rel="stylesheet" type="text/css" href="../support/mystylesheet2.css">
</head>


I soon realized that this was not the most efficient way of doing this. Using the same concept as osCommerce uses, I put the link list in a separate file in the includes directory. I named it header_css.php. Then using Notetab Pro, I replaced the link to stylesheet.css in every catalog file that used it, with the code to include the new file:

<?php
/* stylesheets */
if (file_exists(DIR_WS_INCLUDES . 'header_css.php')) { require(DIR_WS_INCLUDES . 'header_css.php'); }
else { echo '<link rel="stylesheet" type="text/css" href="stylesheet.css">' . "\n"; }
?>
</head>


I set it up to replace the existing link tag, but it could just as easily be added directly below the link tag, like this:

<link rel="stylesheet" type="text/css" href="stylesheet.css">
<?php
/* additional stylesheets */
if (file_exists(DIR_WS_INCLUDES . 'header_css.php')) { require(DIR_WS_INCLUDES . 'header_css.php'); }
?>
</head>


Order is important, so the default stylesheet needs to be listed first, in case you've made any changes to the same elements in your stylesheet.

I use this with just the link tags in header_css.php, and it works fine. But it would be fairly easy to use different stylesheets based on the calling page using a conditional statement.

As of 8/16/2006, the osCommerce version of the site is only on my development server (on my computer). However, the url is http://www.callofthewildphoto.com/. I'll post here when the changes are online.

-Skittles
My OSC site is now live, and features a CSS layout. Swing by and check out my photography, as well as the site design.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic