Show Hide (sidebar) gadgets
UPDATE 10/5: I’m releasing the v2 on this.
Lest you thought we disappeared… I have a script for you! ![]()
This one is not an easy one to implment, but there’s lot of instructions to help you along the way. However, I STRONGLY suggest you have some knowledge of PHP before you attempt this one. The idea here is - lets say you have a lot of junk in your sidebar. Maybe some users are interested. Maybe not. With this script, your users can customize the page… showing/hiding whatever sidebar elements they want. All the info is stored in a single cookie.
(V2 lets you rearrange the order of the gadgets by moving one of them to the top. The one drawback here is that the way the script is written - you kind of have to have your “gadgets” all stacked together. You could, with some tweaking in v1- scatter them… so I’m leaving both up for downloading depending on what you want to do)
Here is the demo page (v1)
(fyi - that demo page looks like POO! especially on a Mac… but it’s just a proof of concept)
Here is a zip with the code (v1)
Here is the demo page (v2)
Here is a zip with the code (v2)
As I warned in the instructions: I make no guarantees. It’s free, okay? Use it. Edit it. I’d love a link back here.
But unfortunately I have very little time for support. You’re always welcome to post a comment here to see if there’s someone out there that can help you. (*please note: if there are already comments here - PLEASE READ THEM before posting your comment - the problem may already have been addressed by someone else)
Enjoy!
(P.S. Thanks to Promoguy for his help/inspiration on this)
October 3rd, 2002 at 3:41 pm
Here is a zip with the code
There’s no link to the download!
October 3rd, 2002 at 3:49 pm
DOH! Sorry about that. All fixed
October 3rd, 2002 at 5:51 pm
OOOOOoooooh, neat demo.
October 3rd, 2002 at 6:53 pm
Way cool goddessJenn!
Nice way to make a lot of info available on the index page.
October 4th, 2002 at 11:37 am
Instead of using it for sidebar content, you could also use this for showing/hiding the ‘more’ and/or ‘excerpt’ of an entry. For an example of what I mean, check out my demo here.
October 4th, 2002 at 12:27 pm
I have this working on my site, if you would like to see it in action. One on the left sidebar, one on the right. Hope to add more soon.
Thanks Jenn!
October 4th, 2002 at 11:15 pm
Jason - NEAT! I like that idea.
October 5th, 2002 at 3:36 am
i’ve never visited your site before, but i have to tell you that if i based my opinion on this script alone - nice effing work.
thanks
October 5th, 2002 at 7:40 am
Oooh, just what I need to get “sidebar mania” under control.
October 5th, 2002 at 7:48 am
That is really cool — does it *work* on a Mac or does it just look icky? Whenever I design, I have to consider my husband because he’s a Mac user, and I’ll be switching in the next six months so I try to keep these things in my head — and saved for future reference in text!
October 5th, 2002 at 8:07 am
Yes - it works on a mac… The problem with the demo is that I just threw it together to show how it works.
All the code is *server side* so it will work on ANY platform.
October 8th, 2002 at 8:58 am
So, tell me about your perfect sidebar - lots of stuff, a little? Do you use my sidebar or your
October 14th, 2002 at 10:29 am
Heya, totally love this script! It’s something I’ve been looking for for ages! I was just wondering, did anyone here try to install this with skins (I have mine working with Amy’s tutorial over at Domesticat.net). If so, does anyone have any pointers for me? I’d love to have both working at the same time, but I’m a little unsure of how to go about it.
November 2nd, 2002 at 5:02 pm
Is it possible to move a gadget up by one block instead of all the way to the top?
Thanks for this great script!
November 2nd, 2002 at 5:11 pm
When coding, it was simpler to move it up to the top… I probably won’t have time to come out with a “version 2″ of it, but I’m sure it could conceivably be done. I’m sure it’s not that difficult - it just wasn’t worth it to me to do it…
You’re alway free to hack the code and see if you can figure it out
(If you do, I’d love it if you posted the link in the comments…)
November 2nd, 2002 at 6:41 pm
Here’s what I came up with. I’m a newbie to PHP so please tell me if I made any mistakes or if there’s an easier way to do it.
Instead of the following code:
$strToShow = $thisGadget;
for ($x=0; $x
December 1st, 2002 at 2:14 pm
That’s wonderful! yay, thanks, Jenn you’re a star! exactly what I was looking for
December 2nd, 2002 at 11:32 am
Something to add here - I was having problems with refreshing the page because my “gadgets” are all PHP includes - so basically, the show/hide *was* working (the hide and show links were alternating correctly) but you needed to refresh the page to actually see the content of the different gadget includes, and that meant going to the location bar and stripping away the setcookie?etc string to only have index.php (normal browser refresh would refresh the whole url + setcookie? string).
So, I just checked around a bit on the php manual pages and other scripts and found that by adding all this stuff:
header(”Expires: Mon, 26 Jul 1997 05:00:00 GMT”); // Date in the past
header(”Last-Modified: ” . gmdate(”D, d M Y H:i:s”) . ” GMT”); // always modified
header(”Cache-Control: no-store, no-cache, must-revalidate”); // HTTP/1.1
header(”Cache-Control: post-check=0, pre-check=0″, false);
header(”Pragma: no-cache”); // HTTP/1.0
session_cache_limiter(’private_no_expire’);
session_cache_limiter(’nocache’);
header(”Location: $HTTP_REFERER”);
exit;
after the last line in the script, (ie. after the last setcookie(etc.) line), the page refreshes correctly by going to the url (index.php or anything else) rather than the url plus query string.
Now I’m a php newbie so I have no idea if all those headers are necessary but it was only after adding them that I could get the whole thing to work without having to reload the page manually.
December 2nd, 2002 at 12:14 pm
Great job Monica! When I get a moment, I’ll add that into the instructions on the download…Thanks for sharing that.
February 5th, 2003 at 5:48 am
My problem being that I can’t stop adding sidebar stuff
February 22nd, 2003 at 9:42 pm
inspired by this but put off by the complicatedness* of the php, i ventured out into the big scary world
February 22nd, 2003 at 9:57 pm
inspired by this but put off by the complicatedness* of the php, i ventured out into the big scary world
February 26th, 2003 at 9:54 am
anyone having trouble getting new gadgets to appear after the user has visted the site once already? even after refresh they are not appearing. the new gadget only appears after deleting the local cookie.
February 26th, 2003 at 10:24 am
Yeah, if you ADD new gadgets, the current script won’t automatically show it for repeat visitors. Since they already have a cookie, it doesn’t know to look for the new setup…
There’s a workaround, that will check the length of the gadgets cookie, and if they have an older version, it will tack on the new gadgets at the bottom…
(fyi - the max. number of gadgets you can ever have is nine… I know, it’s a design flaw…)
In any case, lets say you used to have *6* gadgets and now you have *9*…so you’d now have:
$numOfGadgets = 9;
And here’s an additional block of code to add below that declaration…
if (isset($_COOKIE['gadgets']) && strlen($_COOKIE['gadgets']) < $numOfGadgets) {
$newCookieString = $_COOKIE['gadgets'].”111″;
$_COOKIE['gadgets'] = $_COOKIE['gadgets'].”111″;
setcookie(”gadgets”,”$newCookieString”,time()+126144000,”/”,”.YOURDOMAIN.COM”,0);
}
Obviously change YOURDOMAIN.COM and note the THREE “1″s - because we’re adding THREE new gadgets.
THEN, your three new gadgets will be added to the bottom of your list as a default, here’s the code that will do that:
if (isset($_COOKIE['gadgetOrder']) && strlen($_COOKIE['gadgetOrder']) < $numOfGadgets) {
$_COOKIE['gadgetOrder'] = $_COOKIE['gadgetOrder'].”789″;
}
You see the “789″ part… that’s because we already have 1-6 for the first 6 gadgets. Gadget 7, 8, and 9, will be tacked on at the end… I guess technically you could move it to the front, if you wanted to, but this way it doesn’t upset the current order of your users gadgets…(They can easily move them to the top if they want to)…
I’m not the best at instructions… and especially with this script being as crazy as it is… I hope that makes sense… :-\
March 7th, 2003 at 8:34 pm
One of the tricks I’ve set up on the veiled4allah index page is to allow visitors to show or hide the sidebar blocks. I can’t stop adding sidebar stuff, but not everybody wants to look at all of it. Now…
May 7th, 2003 at 10:39 pm
Behold, the answers to your plagued problems with my sidebar being too long are gone! Now you can click HIDE to get rid of any section you don’t care about. And, should you change your mind later, you can always click SHOW. All via the magic of cookies…
May 20th, 2003 at 4:09 pm
How did you do the “Restore sidebar boxes to their defaults” ? Is that extra code? Thanks Jennifer!
May 21st, 2003 at 9:45 pm
In the download there’s a section that looks like this (with comments removed):
if (!isset($_COOKIE['gadgets'])) {
setcookie(”gadgets”,”111″,time()+126144000,”/”,”.YOURDOMAIN.COM”,0);
$gadgetstemp = “111″;
}
You can change it to this:
if (!isset($_COOKIE['gadgets']) || isset($getdefaultgadgets)) {
setcookie(”gadgets”,”111″,time()+126144000,”/”,”.YOURDOMAIN.COM”,0);
$gadgetstemp = “111″;
}
or this if you added gadgets and making sure they’re seeing all the gadgets including the new one (see comments above for what I’m talking about):
if (!isset($_COOKIE['gadgets']) || isset($getdefaultgadgets) || (strlen($_COOKIE['gadgets']) < $numOfGadgets) ) {
setcookie(”gadgets”,”111″,time()+126144000,”/”,”.YOURDOMAIN.COM”,0);
$gadgetstemp = “111″;
}
Then on your page a simple link:
<a href=”<? echo $PHP_SELF; ?>?getdefaultgadgets=1″>Restore sidebar boxes to their defaults</a>
June 1st, 2003 at 1:34 pm
For this code that a visitor posted avobe for moving the boxes up by one instead of all the way to the top, there are some errors on it and it won’t workf or me. Any ideas anyone? Please?
$pos = strpos($gadgetordertemp, “$thisGadget”);
if ($pos != 0) {
for ($x=0; $x if ($x == $pos-1) {
$strToShow .= substr($gadgetordertemp, $x+1, 1);
$strToShow .= substr($gadgetordertemp, $x, 1);
$strToShow .= substr($gadgetordertemp, $x+2);
break;
} else {
$strToShow .= substr($gadgetordertemp, $x, 1);
}
}
}
September 2nd, 2003 at 4:27 pm
show/hide sidebar gadgets…
November 5th, 2003 at 6:28 pm
See what I’ve done? The side bars (just left for now) are collapsable, and not in the stupid way that the blogrolling is collapsable… It actually doesn’t transmit the data if it doesn’t need to, meaning an even quicker download…
August 15th, 2004 at 5:10 pm
I’m currently installing the show/hide sidebar gadgets script, from scriptygoddess. Because I don’t want to have the script included on…