Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-08-24 13:45:06

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Site Display: User Preferences

Finally getting some work done on my own site (so overdue) and I am building 2 different style sheets…

1. What is the best way to switch style sheets in TXP? I know how to do it with static files but since the CSS is stored in the database I am not 100% sure how to get this working

2. Is there a way that the user’s preference can be saved so that each time they visit, their theme of choice is already displayed?

Thanks in advance

Offline

#2 2006-08-24 14:13:48

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Site Display: User Preferences

You’re not going to be able to use the <txp:css /> tag. But you can still contain all the css within txp.
They use the txp:php to check for a cookie whenever someone visits.

What you do then is this:
<code>
<ul><li><a href=“index.php?css=default”>Default CSS</a></li><li><a href=“index.php?css=alt”>Alternate CSS</a></li></ul>
</code>

Put this at the top of the default page:
<code>
<txp:php>
if(isset($_GET[‘css’]))
{
$getcss = $_GET[‘css’];
setcookie(‘acedubscss’, $_GET[‘css’], time()+60*60*24*30, ‘/’, ‘.mydomain.com’);
} else {
$getcss = ‘’;
}
</txp:php>
</code>

Then you just need to check to see what the cookie is set to when you are writing the css link:

<code>
<txp:php>
if($_COOKIE[‘acedubscss’]==‘alt’ || $getcs==‘alt’) {
echo ‘<link rel=“stylesheet” href=“textpattern/css.php?s=alt” type=“text/css” />’;
} else {
echo ‘<link rel=“stylesheet” href=“textpattern/css.php?s=default” type=“text/css” />’;
}
</txp:php>
</code>

Last edited by Walker (2006-08-24 14:56:10)

Offline

#3 2006-08-24 14:31:59

hcgtv
Plugin Author
From: Key Largo, Florida
Registered: 2005-11-29
Posts: 2,722
Website

Re: Site Display: User Preferences

Can’t wait for the send to how-to button ;)

Walker, you answered a question I would of had down the road, thanks.

Offline

#4 2006-08-24 14:36:17

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Site Display: User Preferences

I fixed my code above. There was one thing wrong and I had also neglected to close my unordered list.

Offline

#5 2006-08-24 14:56:54

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Site Display: User Preferences

p.p.s.

That’s a 30 day expiration on this cookie. It can be made longer or shorter.

Offline

#6 2006-08-24 17:00:02

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: Site Display: User Preferences

Man, this looks super legit… thanks so much :)

Just one question… in your example both style sheets are linked on the page. I would like to only have the link to the other CSS. In other words, if you are viewing default, you only see the link to “Alt” and vice versa.

Would this work?

bc..
<txp:php>
if($_COOKIE[‘acedubscss’]==‘alt’ || $getcs==‘alt’) {
echo ‘<li><a href=“index.php?css=default”>Switch to Default</a></li>’;
} else {
echo ‘<li><a href=“index.php?css=alt”>Switch to Alternate</a></li>’;
}
</txp:php>

Offline

#7 2006-08-24 18:15:06

Walker
Plugin Author
From: Boston, MA
Registered: 2004-02-24
Posts: 592
Website

Re: Site Display: User Preferences

yes.

just make sure that second test case is $getcss not $getcs.

I literally wrote that code off the top of my head. You might need to play with the link that’s being output (make it an absolute rather than relative link) but the rest should &#42;fingers crossed&#42; work.

Last edited by Walker (2006-08-24 18:17:27)

Offline

Board footer

Powered by FluxBB