Jump to content

Recommended Posts

Posted

I'm running a site where the background color and text-box colors are determined by a CSS stylesheet -- I would like to skin the site (nothing too complex, just differing color schemes), and I have two questions.

 

1) What would be the quickest and easiest way to have the site load a RANDOM style-sheet on each pageview? My knowledge of coding is really limited to CSS and HTML, so if I'm going to have to use something like PHP links to examples would be appreciated.

 

2) Is there any way to graft a preference for the skin on the main site into the user preferences of a phpBB, so that a user who opts to have phpBB "remember" them can have a skin of their choosing loaded on the main site?

 

Thanks for your help, I'm still a relative newbie at site design.

 

~ anatole

Posted

Hi.

 

If you want to load a random stylesheet, you can do that with either JavaScript or PHP.

 

With JavaScript, you could do something like this:

 

>.....
<head>
<script language="JavaScript">
<!--
  var style_count = 5; // The number of stylesheets you have
  stylesheet = '<link rel="stylesheet" href="styles';
  stylesheet += Math.ceil(Math.random() * style_count);
  stylesheet += '.css" />';
  document.write(stylesheet);
//-->
</script>
.........
</head>
.........

 

style_count is the number of stylesheets you have available.

The only thing you must do is name your CSS files like "stylesN.css", with N ranging from 1 to "style_count ".

In my example, N could be 5 at max.

 

If you want to do it in PHP, it's easy, too:

 

>.....
<head>
<?php
  $style_count = 5; // The number of stylesheets you have
  $stylesheet = '<link rel="stylesheet" href="styles';
  $stylesheet .= rand(1, $style_count); // Generate a number between 1 and style_count
  $stylesheet .= '.css" />';
  echo $stylesheet;
?>
.........
</head>
.........

 

 

About your second question, it can be done but it requires that you make changes to phpBB's database, and code your website in a way that it gets that information from the database. It shouldn't be too hard but I don't have the time to look into that, right now. I'll explore that later and I'll let you know what I come up with.

Posted

I agree with borfast.

 

You could even have a separate page where the user could modify style sheet (skin) by picking colors, fonts sizes, font style, etc.

 

The info would post into a database table that's linked to the user id (since you're using phpBB... otherwise use a cookie).

 

The info could be serialized and saved as a single sting in the database so it wouldn't take up much room.

 

Then, of course, you have a default skin for everyone else.

 

It starts to get a bit more complex because then you have to edit phpBB code to pull style sheet out of database and read it... but it's not a monumental task.

 

This would be pretty darn cool, an infinite number of possible skins... all chosen by the user.

 

You'd want to place some limits on the styles avail so the page wouldn't break with extra huge fonts.

 

This is the kind of idea that just seems like someone else would have thought of before. I really wouldn't be surprised if a mod was already written to do all or most of what I've described here.

 

You might do a search for phpBB mod or maybe search the phpBB forum for the mods they currently have available.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...