When I made Collapsible Comments plugin I was thinking that it would be a great idea to make elements on a post or page to collapse and expand by demand.

Till now, I could only achieve it by using the Collapsible Comments code, along with it’s basic usage, to have collapsible comments. But then i thought, why not trying to have a button in my editor to give me the code when needed it instead of copying and pasting all the time? And why not having an independant plugin just for collapsing blocks in a post? That’s how i made Collapsible Elements plugin!

Collapsible Elements version 2.2
Updated @ 21/07/2008
Download Collapsible Elements
(from the Wordpress Repository)

  • Description

Collapsible Elements adds a button to the code editor which creates the code for having multiple collapsible elements in a page or post. It’s a really simple plugin which can help you making long posts smaller and smarter with style.

  • Usage V2

Right after the succesfull installation go to your dashboard and you ll find an option page under MANAGE named XCOLLAPSE. Choose a container from TABLE, SPAN or DIV and then write down a default style in the box. After that UPDATE and your options are saved till next time you ‘ll need to change them.

Then, you can see a new button at the CODE editor with the name XCollapse. Now you can click it wherever you want inside a post and it will bring you the code for a collapsible element which is divided in two parts, a code for the link and a code for a collapsible element which will be in the “container” you ‘ve just set. All you have to do is replace the sentence “REPLACE WITH LINK ELEMENT HERE…” with your own words. Then replace the sentence “REPLACE WITH COLLAPSIBLE ELEMENT HERE…” with anything you wanna have collapsed. It could be an image or a paragraph or whatever you have in mind. You could also try to style the table if you dont like it transparent. Save and preview whatever you just did!

Note the xcollapse function and the ID, both of them are important (and also see the display: none attribute at style which it will hide the container’s data by default). Now watch the result by clicking the following link:

After puting the code of a collapsible element in the CODE editor you could then return to the VISUAL editor and continue there. The code editor will just have the button and the code. Whenever you want to put another collapsible element go to the code editor and repeat the proccess. If you wanna change the style of a collapsible element you can correct it in html editor or create a new default style (or container) under manage in XCollapse Options page.

  • How does it works

First it generates a random number ID which will be used marking the id’s of the collapsed elements. That number is important because it must be unique in the same page/post. Then it creates the needed code with a link and a container for the data we wanna have collapsed. I can have whatever I want inside the container and I can also create multiple collapsible elements in a page or post each time i use the XCollapse button.

In version 2.X i decided to make an option page under Manage because some of you preffered DIV’s instead of tables and wanted their own default style to use. Can be easily changed for individual posts anyway or set a new default container/style each time is used.

  • Important Note

If you ever uninstall Collapsible Elements plugin the collapsed data in your posts will be hidden until you change the “display: none attribute of container’s style and remove the link.

  • Credits

Collapsible Elements plugin is based on the Javascript i found on Arvind Satyanarayan example which toggles the visibility of multiple elements on a page, see the code in his website. I also used a function to insert a quicktag button which was taken from the Iimage Browser plugin and the edInsertContent function which is included at quicktags.js file and was made by Alex King. At last i wanna thank Matteo for his comment.

PS: See a more complicated use of Collapsible Elements plugin as an example with three collapsible links inside a fixed table to simulate 3 text collapsible columns.

The Good The Bad The Ugly

The last example had parts of the Declaration of Independence of Cyberspace.

Last Note: Collapsible Elements plugin is aiming to those webmasters who wanna have more capabilities formatting the expandable content in many ways. But if you find it too complicated for you and you just want something more simple, i suggest that you also try Collapsing Objects plugin of DrLebowski. If you like it tell him that ..::DeUCeD::.. thinks that VFR is *not* a bike but feels more like a “washing machine“. Real bikes *DO NOT* have a fairing but lets you fight the wind alone…

ADD-ON
Thunder-man has created a small handy portable version of a script that can generate the code for Collapsible Elements named CE-Generator! More info and download can be found on it’s page.

131 Comments

Go to Comment Form »
  1.   evaNz said:

    14-12-2007 @ 14:08

    [-]

    Cool! I’m using it! keep it up! Love u!

  2.   Matteo said:

    13-01-2008 @ 20:34

    [+]

    Hello I slightly changed the function xcollapse (in ccomments.js) as follows function xcollapse(id) { var element = document.getElementById(id); if(element != null) { ... ...

  3.   ..::DeUCeD::.. said:

    13-01-2008 @ 20:42

    [+]

    Seems useful Matteo, I 'll have to test it and think about your change. I' ll get back to you soon. BTW, the "double-click bug" was fixed with v.3.1 and it was caused by an extra DIV i had to the ... ...

  4.   ..::DeUCeD::.. said:

    14-01-2008 @ 13:33

    [+]

    Well Matteo, i tested it many times and it worked but didn't seem to make any difference. As i said the “double-click bug” was fixed with v.3.1 and you can always add style information in a se... ...

  5.   Jones said:

    02-03-2008 @ 09:51

    [-]

    Hi
    Is the colpase just for blogs. Is it possible to use in html?
    It’s really cool, I lik it
    Keep up doing great things
    j

  6.   ..::DeUCeD::.. said:

    02-03-2008 @ 15:13

    [+]

    Hey Jones, You can easily use it in html page. The easiest way is to take the plugin and save it somewhere. Find the javascript file within it, open it and copy it somewhere in your HEAD section of... ...

  7.   RedMoze said:

    04-03-2008 @ 12:21

    [-]

    thks, very nice plugin.

  8.   Marty said:

    14-03-2008 @ 15:27

    [+]

    I'm just curious why you used the <table> element instead of a <div> for your container. Without looking at the full code yet (which would probably make it somewhat evident, even to a non... ...

  9.   ..::DeUCeD::.. said:

    14-03-2008 @ 15:34

    [+]

    Some of you may ask why i used tables as a container. Well you can use whatever you want but i ‘ve noticed that, in some cases, WordPress strips the DIVs so i preffer TABLES as containers of an elem... ...

  10.   Pierre K. said:

    14-03-2008 @ 19:39

    [-]

    Very nice plugin. But is it a way to make it unobtrusive : showing the collapsing elements when Javascript is desactived instead of hiding them ?

  11.   tal galili said:

    14-03-2008 @ 23:28

    [-]

    Very cool, thanks !
    I wish I could track what people are clicking…

    Tal.

  12.   ..::DeUCeD::.. said:

    15-03-2008 @ 08:12

    [+]

    Pierre the Javascript function toggles the visibility of an element between two conditions: it does the show/hide and also the "container" (DIV, TABLE, SPAN, whatever) has to have a default attribute.... ...

  13.   Skylog » Blog Archive » links for 2008-03-15 said:

    15-03-2008 @ 08:17

    [-]

    [...] Collapsible Elements (tags: wordpress plugin) [...]

  14.   Travis said:

    18-03-2008 @ 16:07

    [+]

    Can I somehow trigger my hidden table to become visible when the page loads by putting something in the url? ie: I have my comments hidden by default. When someone opens the comments and then adds a... ...

  15.   ..::DeUCeD::.. said:

    18-03-2008 @ 16:29

    [+]

    Well Travis i think that it can be done. I have something in my mind but i want to test it first. I ll post an answer soon and i will also send you an e-mail about the solution. That may be a standard... ...

  16.   marc said:

    19-03-2008 @ 01:46

    [-]

    I installed this plugin but as yet have not gotten it to work correctly. When hitting the link to expand what is hidden it just jumps to the top of the post vice opening.

    This post has an example.

  17.   ..::DeUCeD::.. said:

    19-03-2008 @ 10:32

    [+]

    Hey marc I did saw your page and the code seems right. I made a test blog with same theme as yours and activated some of the other plugins i saw that u use like bad behavour and ubernyms. Everythin... ...

  18.   marc said:

    19-03-2008 @ 11:46

    [-]

    Yep, that was it. I think the js file may have been corrupted, a delete and reload cured the problem.

  19.   ..::DeUCeD::.. said:

    19-03-2008 @ 11:48

    [-]

    I ‘m glad you solve it :)

  20.   Travis said:

    19-03-2008 @ 20:30

    [+]

    Hey Deuced. About expanding a hidden element from the url... For testing, I tried making a separate php file that pulled in the required wordpress and collapsible elements files, redirected the p... ...

  21.   Travis said:

    19-03-2008 @ 20:33

    [-]

    had some tags that got lost in the above comment that make it confusing looking.

    –execute the script from the head section.

  22.   ..::DeUCeD::.. said:

    19-03-2008 @ 22:27

    [+]

    Hmm... Let me stick 'em all together. You are using Collapsible Elements for the whole comment block BUT you want the last comment to be visible. Before we go on and without having to reinvent the... ...

  23.   marc said:

    20-03-2008 @ 21:37

    [+]

    Again thanks for assisting in finding the js file error, the plugin works great. One last question, being far from an expert code monkey I have not figured out how to style the table for this plugi... ...

  24.   Beth said:

    20-03-2008 @ 23:47

    [-]

    Can it be used in the sidebars?

  25.   ..::DeUCeD::.. said:

    21-03-2008 @ 08:56

    [+]

    Hey Marc I'm gonna give you a basic code but you r gonna have to experiment yourself for having the exact results that will match your theme in your blog. First of all you have a white background so ... ...

  26.   ..::DeUCeD::.. said:

    21-03-2008 @ 10:27

    [+]

    Hi Beth As i 've told, it can be used as a "swiss knife" and that mean's everywhere! If you see my previous comment you will notice a collapsible table INSIDE my collapsible comment. As a matter o... ...

  27.   marc said:

    22-03-2008 @ 00:19

    [+]

    DeUCeD, thanks again but I'm afraid I don't fully understand where the css code should be used. Is it placed each time you use xcollapse? Should that be placed into the style sheet? Or should it... ...

  28.   ..::DeUCeD::.. said:

    22-03-2008 @ 16:01

    [+]

    Marc, the simplest way is to have it AS IS in your code editor and it will work. If you wanna have something in CSS then you have to add a class to the table. But try the manual way, find the style th... ...

  29.   CT said:

    23-03-2008 @ 21:18

    [+]

    First, great plugin, thank's for all the work! Second, is there a way to have collapsible elements stacked on top of one another (such as images, or bulleted words )without the space in between? ... ...

  30.   marc said:

    23-03-2008 @ 23:59

    [+]

    That's how I thought the css worked, after trying it the second time it still has failed to work properly. In addition as you can see in this post the collapsed elements load open vice closed. I re... ...

  31.   ..::DeUCeD::.. said:

    24-03-2008 @ 07:58

    [+]

    Marc! You just copied table's code! As i see you don't have lot's of experiance so the first thing you should ALWAYS do when playing with ANY code is find a decent editor (google for notepad2) or just... ...

  32.   ..::DeUCeD::.. said:

    24-03-2008 @ 08:05

    [+]

    CT let me try it here... CE a CE b CE c CE a ELEMENT HERE... CE b ELEMENT HERE... CE c ELEMENT HERE... If that's what you are trying to do, afte... ...

  33.   marc said:

    25-03-2008 @ 09:22

    [+]

    Actually I've been messing with this blogging stuff for about 5 years. Unfortunately I over looked the "fancy" quote marks in the code. Thanks for all your help, and frankly look forward to an upda... ...

  34.   Travis said:

    25-03-2008 @ 18:03

    [+]

    Hey Deuced, Referring back to comments 15, 21, 22 about opening a collapsed element from the url. To briefly restate, I had the entire comment box tucked into a collapsible table. All comments wer... ...

  35.   ..::DeUCeD::.. said:

    26-03-2008 @ 08:42

    [+]

    Travis, first of all i'm really glad you made it work for you! That's exactly when they say "Code is Poetry"! Now let say a few things. Collapsible Elements in a page are elements loaded but jus... ...

  36.   the klaus said:

    02-04-2008 @ 18:07

    [+]

    Thanks a lot! I made a little hack, because my collapsable elements are sometimes really long and so I had inserted only one line code more after the last line text und the : Well... I cant inse... ...

  37.   ..::DeUCeD::.. said:

    03-04-2008 @ 23:20

    [+]

    U R right klaus, a similar approach is Collapsible Comments where i ve put a "close" link at the bottom. Next version of Collapsible Elements should have the ability to change your code and it will re... ...

  38.   John said:

    09-04-2008 @ 14:18

    [-]

    Hey, how can i use this for Archives, i would like to display the archives category wise and post should be collapsible… please advise..

  39.   ..::DeUCeD::.. said:

    09-04-2008 @ 15:06

    [+]

    Hey John, please read No 27 comment which is an answer to Beth on if Collapsible Elements can be used in the sidebar. Generally YES, you can use it anywhere but you have to manually put the code where... ...

  40.   Nicole said:

    11-04-2008 @ 12:48

    [+]

    Hi there, great plugin, just what i need however i have wordpress 2.5 and when i click the "XCollapse" button in my HTML view nothing happens... no code is added to the editor as you describe above..... ...

  41.   ..::DeUCeD::.. said:

    11-04-2008 @ 13:32

    [-]

    I’m using WP2.5 and if you are on HTML CODE editor it *should* provided you the code. Could you installed it again? Remember that it works ONLY in HTML view, *NOT* in VISUAL Editor.

  42.   Nicole said:

    11-04-2008 @ 14:28

    [-]

    I have worked out the problem… it doesnt work in ie7 - its fine in FF. Are you aware of this?

    thanks
    Nicole

  43.   ..::DeUCeD::.. said:

    11-04-2008 @ 15:11

    [+]

    NO! To tell you the truth i 've run several test to IE6 but never thought that it there would be a problem in IE7. I 'll have to recheck it tomorrow in IE7 and confirm it. Thanx for letting me know ab... ...

  44.   Nicole said:

    12-04-2008 @ 01:02

    [-]

    Cheers for the comment on the site. I check back tomorrow to see if you can find a fix. otherwise im happy to use FF. thanks for the plugin. its gonna be great for my site.

  45.   ..::DeUCeD::.. said:

    14-04-2008 @ 09:05

    [+]

    Hey Nicole, sorry for the delay but i don't have IE7 at home so i could only test it @ work. But WP2.5 along with IE7 DOES work for me. Unfortunately I cannot duplicate the error you have but i'm thin... ...

  46.   Mark A. said:

    25-04-2008 @ 01:03

    [+]

    Thank you for this plugin, it works great. Not sure if there is a plugin conflict though or something else, but I run another plugin called WP-Print. WP Print usually formats blog posts nicely for the... ...

  47.   ..::DeUCeD::.. said:

    25-04-2008 @ 01:25

    [+]

    Well i tried it and i can only guess that it sees the Collapsible Element as a Link and that's why it prints the link but not the content. It has also lots of rewrite rules to try and guess what exact... ...

  48.   Joo Juice » Just a side note. said:

    30-04-2008 @ 09:17

    [-]

    [...] called Collapsible Elements and it works ANYWHERE on your web site! go over to Deuced and check it out! tell him what site you came from and he’ll give you ..um .. some of his [...]

  49.   Andrea said:

    30-04-2008 @ 21:12

    [-]

    Thank you so much for this plugin. I’m super new at all of this, as in SUPER NEW, and I found this plugin dead easy to install and use. Your instructions are clear - really appreciate it!!

  50.   ..::DeUCeD::.. said:

    01-05-2008 @ 14:35

    [-]

    I’m glad you finded usefull Andrea!
    If you ever need further assistance let me know.

  51.   FruityOaty said:

    02-05-2008 @ 06:25

    [+]

    Unfortunately, it's incompatible with this excellent WordPress Lightbox plugin called "WP 2.5 Gallery Lightbox" (which is one of the only Lightbox plugins out there that works without issues with the ... ...