Collapsing Page Menus Plugin
Wednesday, October 4th, 2006
UPDATED! This plugin now works in WordPress versions greater than 2.0!Collapsing Page Menus is a WordPress 1.5+ plugin that generates a collapsing menu of your site pages as an unordered list. The current version is 1.1 and was released on May 23, 2007.I have not tested this plugin under WordPress versions earlier than 1.5. However, I suspect it works correctly in most WordPress versions.Please submit any comments, bug reports, and other issues in the comments to this post.
Download
Collapsing Page Menus[.zip ]
Installation
Collapsing Page Menus is installed by decompressing the zip file above and uploading the collapsing_page_menu.php file to your plugins directory (/wp-content/plugins/) and then enabling the plugin in the WordPress Plugins administration screen.
Use
Once you’ve activated the plugin, you can produce a collapsing page menu by inserting the following in your template file:< ?php echo collapsing_page_menu(); ?>The function also has 6 parameters that you can use to tailor the display of the unordered list.collapsing_page_menu ( $root_id = 0, $order_by = 'menu_order', $order_dir = 'ASC', $css_li = 'page_item', $css_li_selected = 'current_page_item', $current_id = '' )
- $root_id: The parent page ID. If you’d like to have all of your pages in the menu, use 0. To show only sub-pages of a particular page, use that page’s ID. Note that the given page will not display as part of the menu.
- $order_by: The database field to use for record ordering.
- $order_dir: The direction in which to order the pages.
- $css_li: The CSS class for every page li.
- $css_li_selected: The CSS class for the current page li.
- $current_id: Override in cases where the $post variable is compromised or inaccurate. Most of the time, you won’t need to use this parameter.
If you have found the plugin useful, please leave me a comment with a link to your site and I will add it here.
Version History and Changelog
- 1.2 - 2007-07-19 Corrected to fix a bug that displayed draft pages.
- 1.1 - 2007-05-23 Corrected to fix a bug that didn’t display menus below the first level.
- 1.0 - 2007-05-18 Updated to handle WordPress’s new method of storing pages.
- 0.1 - 2006-10-04 Initial release.
Related Plugins
TAGS: comments, hacks, menus, navigation, pages, php, plugins, projects, wordpress



105 Comments to “Collapsing Page Menus Plugin”
Flightpath: A Blog from Hotrocket, An Interactive Agency, and Rocketfuel, Our Production Company » Blog Archive » Cam’s Hacks: Collapsing WordPress Page Menus
October 4th, 2006 at 3:45 pm
[…] Check out the plugin at Collapsing WordPress Menus. […]
Blendlab.com » Blog Archive » Pimping WordPress
October 4th, 2006 at 3:56 pm
[…] Hopefully the first of many, Cam has developed a pristine plug-in for Wordpress to make collapsable menus a snap. If you think it may be of use, I think you should head over and have a gander. […]
Morktron
November 4th, 2006 at 2:52 am
Amazing Cam, thanks and well done. I got it working and I am no php programmer.
Check it out here: http://www.nidhana.com
(my 1st go at WordPress)
I don’t suppose you can get it to do the same for the ‘Links’ menu?
Anyway, thanks
Cam
November 4th, 2006 at 5:09 pm
Morktron:
nice work on the site; it is… titillating. Since links and link categories can’t be hierarchically organized, it’s not possible to have collapsing menus for them. Sorry
M@X
November 7th, 2006 at 4:07 pm
I like the result Marktron got wiyh this PlugIn
But I don’t know how to do it
In which template to insert the code. Where in existing code? And do I need that parameters? Thanx in advance 
roberto
November 13th, 2006 at 11:48 am
actually it works! It was writing the ul so far and i did not noticed it on the mark up. So… my fault and sweet job!
Gilles France
November 24th, 2006 at 1:54 pm
Excellent !
Simple et efficace merci beaucoup !
Gilles
Cam
November 24th, 2006 at 2:19 pm
Gilles: Bienvenue!
Eve
November 25th, 2006 at 1:52 pm
I am also having difficulty trying to find where in the sidebar template to insert the additional code. Every place I’ve picked so far has caused the print to show up on the webpage. I have cut and paste it exactly as you have it above … where do I insert it and does it need any additonal commands or something before or after it for it to not show up as text on the page? THANKS!!
Cam
November 25th, 2006 at 3:09 pm
Eve: make sure you are using the exact text in the example, including the angle brackets with question marks. Every template is different, so I can’t speak to exactly where in the file it should go.
Jason
November 26th, 2006 at 9:06 am
Hey Cam,
This plugin is very close to what I (and perhaps others, too) are looking for.
What would really cinch it for me would be if root_id could be set to the 1st-level parent of the page you are on. So, for example, if you are viewing About Us > Staff > Board, the plugin would notice the ancestor of About Us and set that as the root_id.
Do you think this is possible? Let me know.
Usando Plugins en wordpress (1ra parte) at Bitácora Taller Multimedia
November 28th, 2006 at 1:30 pm
[…] Plugins destacados Gracias a la investigación de Claudia Rincón para el sitio del Fondo Margot Loyola, destacamos dos plugins para menúes: Collapsing Category Menus Collapsing Page Menus Estos plugins permiten que las categorías de los post y las páginas respectivamente, escondan a sus subcategorías y subpáginas hijas. Sólo cuando uno entra a la categoríoa se desplegan las hijas como pueden ver en el ejemplo que la misma claudia puso en su sitio. Como ven sirve para no atiborrar de links en los sidebar. Luego se coloca el tag php en una lista (li) del sidebar de la plantilla que esten usando o realmente en la parte que ustedes estimen. […]
Vernal » Drupal > Wordpress migration part II: The ultimate Wordpress menu manager
November 29th, 2006 at 10:49 pm
[…] My hunt for a plugin left me passing up the popular Fold Page List plugin and moving onto Collapsing Page Menus by Cam Fraser. It was nearly what I was looking for. […]
Alex
December 5th, 2006 at 3:25 am
Cam
This plug-in looks absolutely fantastic! I think it really adds a professional look and feel to a site.
However, I would like to know whether this plug-in will have a negative impact on search engine rankings? In other words, is it SEO?
Please excuse my ignorance, I’m relatively new to learning about the internet and even newer to wordpress.
In any event, thanks for putting together such a brilliant plug-in and making it available to all of us. Well done and thanks !!!
Cam
December 5th, 2006 at 9:29 am
Alex:
From a “white hat” perspective, it is SEO. As the plugin uses the guid you’ve set up, it is as SEO as WordPress is. If you aren’t using permalinks, it is not as SEO as if you are.
Alex
December 5th, 2006 at 4:57 pm
That’s great news. Once again, thank you very much!
Marsha
December 16th, 2006 at 11:16 am
Yes! This is exactly what I’ve been looking for, and it works exactly the way I want it to work! Now I can have fully dynamic page menus! I have been trying to convert my church’s web site to Wordpress and the lack of dynamic menus had me blocked. Now I can finish. Thank you, thank you!
CEFM
January 4th, 2007 at 11:13 pm
The new 2.1 test relese of WordPress make this plugin display nothing.
Cam
January 5th, 2007 at 9:02 am
CEFM: hmm. I’ll have to check that out, because unless WP2.1 modifies the database architecture or modifies the use of either the global variable $post or $wpdb (all of which seem unlikely), it shouldn’t affect this plugin. I’ll look into it.
CEFM
January 5th, 2007 at 9:22 pm
I believe the DB is different. Thanks I love the plugin.
Koen
January 16th, 2007 at 8:39 am
Great plugin one thing only….
It’s not very handy to style with css listamatics when not identifying the
i would sugest identifying the tags
UL id=”navlist”
UL id=”subnavlist”
this would make it easier to style
AJ
January 22nd, 2007 at 11:20 pm
Hi Cam,
Both the links in the demo area seem to be dead.
I could not get the menus to work, but it may have something to do with the theme I am using.
AJ
AJ
January 22nd, 2007 at 11:37 pm
I am using sidebar widgets, so maybe I am editing the wrong sidebar.php
CEFM
January 23rd, 2007 at 8:34 pm
I asked in the wp-testers mailing list and got the solution to fix this plug-in for the new Wordpress Version 2.1.
Changing this:
$pages = $wpdb->get_results(”SELECT * ” .
“FROM $wpdb->posts ” .
“WHERE post_status = ’static’ AND ” .
“post_parent=$root_id ” .
“ORDER BY $order_by $order_dir”);
to this:
$pages = $wpdb->get_results(”SELECT * ” .
“FROM $wpdb->posts ” .
“WHERE post_status = ‘publish’ AND post_type = ‘page’ AND ” .
“post_parent=$root_id ” .
“ORDER BY $order_by $order_dir”);
Fey
January 24th, 2007 at 3:50 am
Hi,
I installed your great plugins (both collapsing menu thingies) last week and after some minor troubles all went fine.
but this morning I upgraded my blog to v2.1 and found that the collapsing categories still worked but the collapsing pages were nowhere to be seen…
any idea why that would be? or how to make it work again?
thanks so much,
.Fey.
Alasdair
January 24th, 2007 at 4:44 am
Hi there,
This plugin worked great and really enhanced the sidebar, however, I foolishly upgraded to Wordpress 2.1 and it stopped working.
Any chance you could take a look and try and come up with a fix?
Many thanks.
Daniel Hardy
January 26th, 2007 at 10:41 am
For thoose who have upgraded to 2.1, CEFM’s suggestion does fix the problem of absolutely nothing appearing.
But there is still the problem of children page links not appearing where they should.
Chad Day
January 26th, 2007 at 3:10 pm
Try this change, in addition to CEFM’s
change:
if(!$current_id && $post && $post->post_status==’static’) {
$current_id = $post->ID;
}
to:
if(!$current_id && $post && $post->post_status==’publish’) {
$current_id = $post->ID;
}
DB Ferguson
January 28th, 2007 at 9:04 pm
Any chance this could be made into an easy-to-use widget plugin?
Simon
January 29th, 2007 at 10:17 am
Thanks for your hard work, Cam. This plugin would be a dream-come-true except for one small point - how do I exclude specific pages from showing up? I know this is easy with the wp_list_pages tag, but I tried incorporating some of the code from that into the collapsing page plugin, and broke it. Heh.
Any help much appreciated!
Simon
January 29th, 2007 at 10:37 am
oops, sorry, I got my email address wrong in the last message. I am an idiot!
Jason
January 31st, 2007 at 11:45 am
Yes, the above changes by CEFM an Chad worked 100% in 2.1 for me. Thanks everyone!
Jason
Paul
January 31st, 2007 at 12:44 pm
If I’m right… When you have installed WP 2.1 and uses the Collapsing Page Menus Plugin you have get it work with these to modifications:
change:
if(!$current_id && $post && $post->post_status==’static’) {
$current_id = $post->ID;
}
to:
if(!$current_id && $post && $post->post_status==’publish’) {
$current_id = $post->ID;
}
and
Changing this:
$pages = $wpdb->get_results(â€SELECT * †.
“FROM $wpdb->posts †.
“WHERE post_status = ’static’ AND †.
“post_parent=$root_id †.
“ORDER BY $order_by $order_dirâ€);
to this:
$pages = $wpdb->get_results(â€SELECT * †.
“FROM $wpdb->posts †.
“WHERE post_status = ‘publish’ AND post_type = ‘page’ AND †.
“post_parent=$root_id †.
“ORDER BY $order_by $order_dirâ€);
But on which document do I have to change this, sidebar.php? There are no such lines.
Thanks!
Cam
January 31st, 2007 at 2:16 pm
Paul: You’re making those changes in the file you downloaded from this page.
Dave
February 2nd, 2007 at 8:03 am
Firstly, Great plugin. Everything works fine, but in wordpress 2.1 these changes still don’t make the plugin fully functional. If you are viewing a page which is not on the menu, such as a post page, then only the first page hyperlink will work, the rest have / as hyperlinks. Somehow this breaks the chain. For example if you have 3 pages: Home, About, Contact. When viewing a post page (not one of the 3 wordpress pages), then only the Home button will work, the other two don’t go anywhere. But if you then click on Home, all page buttons and sub-page buttons work. Not sure if this is the case for everyone but it certainly is for me.
Hope I’ve not confused anyone, and my apologies if this is something I am doing wrong.
Dave
Dave
February 2nd, 2007 at 8:09 am
CSS Tags - I know that this is possible, but as a CSS Designer, and not a php programmer I am not sure how to do this. Here goes. What I want to do is create a different class for each page item, so instead of just having page_item and page_item_current_page_item, maybe have page_item_$post_title.
The lines of code I need to change are:
$css_li = ‘page_item’ , $css_li_selected = ‘_current_page_item’
to something like:
$css_li = ‘page_item_($page->post_title)’ , $css_li_selected = ‘_current_page_item’
Any help with this would be great, and would make this plugin flawless.
Dave
Fey
February 5th, 2007 at 3:00 am
same question as Simon before me (as I really didn’couldn’t find an answer in the replies):
how do I exclude certain pages?
thanks for answering.
.Fey.
Cam
February 5th, 2007 at 10:43 am
Hi Fey: currently, there’s no way to do that. It is on the list as a desired feature, though.
6 Handy Plugins for Your WordPress-Run Church Website : Church Communications Pro | Church Website Design | Church Marketing
February 5th, 2007 at 10:30 pm
[…] Sidebar Navigation – Check out these two plugins: WP-PageNavi 2.10 and Collapsing Page Menus Plugin Get church marketing ideas, tips and more by subscribing to the Church Communications Pro Email Newsletter Subscribe to the CCP Blog Feed […]
Dennis
February 6th, 2007 at 8:48 am
This is a nice plugin. I followed the instructions above (many thanks) and it seems to be working great except for one issue. For some reason, the sub pages don’t indent. They appear:
main page
sub-page
instead of:
mainpage
sub-page
I’m wondering if this is due to the theme I am using or if I missed something. Any ideas would be appreciated.
Cam
February 6th, 2007 at 11:11 am
Dennis: what is the html code being output? or what is the link to your website?
Vernal »
February 6th, 2007 at 5:29 pm
[…] Here is a list of the plugins I used to make in order to stretch the powers of Wordpress to that of a very feature-rich content management system that maintains the simplicity and user-friendliness of a blog. You can see the results at Craft Emergency Relief Fund.What I think is truly remarkable about using Wordpress as a Content Management System is that it can be twisted and turned in so many ways without even coming close to modifying the core code. Upgrades become a snap and sustainability goes through the roof. I truly believe it is hands-down the best solution for small to medium sized organizations. Breadcrumb by Dan PeverillA simple and wonderful breadcrumb navigation system.Where you’ll see it: Hiding in the green bar at the top of all pages on Craft Emergency Relief Fund.Batch image upload by Tony GamboneBatch Image Upload is pretty simple: It allows the user to upload a large number of images quickly and easily. It’ll even resize them on teh fly. A nice alternative to FTP.Collapsing Page Menus - Vernal Creative Edition by Cam FraserThis is the shiny gem of the collection. Collapsing Page Menus by superstar plugin developer Cam Fraser is the end-all menu solution for Wordpress sites. You can read more about it at my previous entry.Where you’ll see it: Head to an interior page and play with the menu on the left. Notice the nice behaviour. Ooh lala. […]
susan
February 13th, 2007 at 10:29 pm
Hey Cam, Sorry, I goofed the code up on the earlier comment. Here’s the (hopefully) corrected comment.
Thanks, this plug-in is fantastic! And thanks to all you posted about updating it for WP 2.1.
Here are a couple of notes on some items above that may be helpful for others.
1.Cam says:
Once you’ve activated the plugin, you can produce a collapsing page menu by inserting the following in your template file:
< ?php echo collapsing_page_menu(); ?>When you insert this into your sidebar.php page. The php code will need to be updated so that the first bracket ( <? php
2. In Paul’s post from Jan 31st 2007, WordPress nicely formatted the single ‘quotes’ and “double” quotes in the php to be right and left quotes.
However, when you update your collapsing_page_menu.php plug-in, you’ll need to convert these back to " and '
Cheers!
Nate
February 14th, 2007 at 6:22 pm
I just installed Ella and it doesn’t seem to jive with the new Wordpress version. I’ve been using it for a long time and would like to use it again. do you have support for Ella?
Cam
February 15th, 2007 at 8:37 am
Nate: I don’t know what Ella is, sorry.
Gregory Pittman
February 16th, 2007 at 9:21 am
Cam, “Ella” is the nickname for WordPress v2.1.
Nate, follow the instructions others have posted to make the plugin compatible with 2.1. Be sure to read all of them because there are coding “errors” in the update (right and left quotes, spaces in the wrong place, etc.), all of which will cause the plugin to break.
I know it’s on the requested features list, but the ability to exclude specific pages would be awesome!
Amadeo
February 17th, 2007 at 11:07 am
Hello, and thanks for the plugin.
It is working very well for me in WP 2.1, after I modified the code as suggested before.
However, I would like to modify the style of the menu, essentially giving a different colour to the selected subpages, so that they stand out.
I understand it is possible, but cannot figure out what to do. Could anyone give some hints?
Thanks very much!
Mike
February 19th, 2007 at 7:47 am
How Can I exclude pages? I’ve tried to make a exclude option and wrote something in the SQL query but I can’t get the job done. Can anyone help me? Thanks.
Nate
February 19th, 2007 at 1:17 pm
Ella is the newest version of Wordpress 2.1. I had this plugin installed with my last version of Wordpress Ronin. And it worked great. It doesn’t seem to play well with Ella though.
http://wordpress.org/development/2007/01/ella-21/
Nate
February 19th, 2007 at 1:20 pm
Gregory Pittman
Shoot I saw your post right after I made my post above. I’ll give it a dance Greg.
Thanks
Mike
February 19th, 2007 at 11:32 pm
can any one help me? how can I exclude some pages by their IDs?
Nate
February 20th, 2007 at 12:48 pm
Hmm…has anyone got this working for 2.1 yet? I made all the changes listed above, but all I get is an error after uploading and activating this plugin.
sminc
February 22nd, 2007 at 12:17 am
Cam,
Do you have plans to publish a 2.1 ready plugin?
Thanks!
sminc
Scot Hacker
March 6th, 2007 at 2:34 am
Ditto - I’m running 2.1.2 and, even with all of the changes listed above, I’m getting 100% blank output. I’d gladly donate to the developer for a working 2.1 version of this in the very near future.
xerox
March 12th, 2007 at 6:50 am
I am using this plugin, works great, but have one problem. Let say i have navigation like this:
PARENT PAGE
|_ first subpage
|_ second subpage
|_ third subpage
I need, after clicking on PARENT PAGE, to jump on first subpage. There is no PARENT PAGE content, it serves only as a name of group of subpages.
Does anybody have idea? Thanks
Cam
March 12th, 2007 at 8:42 am
xerox: You can do that in your template’s page.php file. If PARENT PAGE is ID 5 and first subpage is ID 6, you’d simply write at the top of the page.php file (before the get_header() call):
if ( is_page(5) ) { query_posts('page_id=7'); }Obviously, this would need to be within the <?php and ?> tags.
Good luck!
xerox
March 12th, 2007 at 11:17 am
Cam: I am greatful for help, it works. Thank you
Daniel
April 11th, 2007 at 5:28 am
Hi. Are there any more examples of this plugin running? The links you have don’t seem to work anymore.
Thanks
Daniel
Kevin
April 27th, 2007 at 5:36 am
I’m going to use this plugin on our company site. I have it working now but I need to tweak it a bit.
Thanks to everyone that submitted help with the code updates I think it may work out.
Thanks,
Kevin
WDStephenson
April 27th, 2007 at 3:27 pm
Hi. Thought you’d want to know that the links to the two demos you mention are bad:
* Genesis
* Hemisphere Engineering Wireframe
Ray
May 17th, 2007 at 11:37 am
Thanks for this plugin, it’s exactly what I’m looking for although I’m not quite sure how to use it (new to PHP & Wordpress).
Currently I’m using the just released Wordpress 2.2. I’ve downloaded and activated the plugin.
But how and where do I call this function collapsing_page_menu() from? sidebar.php? Where should I place it in the file?
Thanks in advance.
raphael
May 18th, 2007 at 7:37 am
after upgrading from wp 2.0.4 to 2.2 it doesn’t work anymore.
have i overlooked anything or do other people experience also problems?
thank you very much
raphael
Cam
May 18th, 2007 at 7:57 am
I have now updated the plugin to work with newer WordPress versions!
Cam
May 18th, 2007 at 7:58 am
Ray: put it in your sidebar.php file.
raphael
May 19th, 2007 at 5:14 pm
hello cameron,
thank you for the update!
after installing version 1.0, the only thing that gets listed under pages is “2.2″
but no menu…
strange, does this make any sense to you?
best raphael
Cam
May 19th, 2007 at 6:03 pm
raphael: give ‘er another download.
raphael
May 20th, 2007 at 1:47 pm
cameron,
the first menu level gets displayed now, but no children…
thank you & saludos
raphael
Cam
May 23rd, 2007 at 10:49 am
The first-level-no-children issue has been corrected and released as version 1.1. Thanks for your help, raphael!
JT
May 24th, 2007 at 3:47 am
is this plugin compatible with widgets? if so, would it still be the sidebar.php file that is modified with the call? or is it the widgets.php file in includes?
alfie
May 25th, 2007 at 11:27 pm
Something is wrong in the code: I am using WP 2.X
I am not seeing any indents in the sub-pages.
When I check the output (HTML), I have:
Level 1
Level 2
Level 21
Level 22
Level 3
Level 4
It seems that the error is in the wrong being outputted instead of a .
Am I the only one to have that ?
alfie
May 25th, 2007 at 11:30 pm
The HTML tags got stripped.
Here is the prob: Just before Level 3, instead of a UL, I am seeing a backslash (LI) and after Levl 4, there is the backslash UL
So, instead of the backslash LI before Level 3, we should have a UL
Brian Jarrett
June 7th, 2007 at 8:35 pm
Just installed on Wordpress 2.2. Working great; just what I needed. Thanks!
BrianJarrett.com » Blog Archive » Cool Wordpress Plugins
June 7th, 2007 at 8:50 pm
[…] Collapsing Page Menus […]
Adity
June 11th, 2007 at 3:59 pm
it works. but how do i exclude pages i don’t want to be displayed in the menu??
jessib
June 18th, 2007 at 1:05 pm
For newer WP versions, it displays drafts and private pages. I removed those by adding a line to make sure the post_status is ‘publish’ in the database call, in the collapsing_page_menu function. Are there preferred ways to do this?
Helder Luis
June 18th, 2007 at 5:33 pm
I need to list the parent pages of a page:
- Main 1
– Sub 1
— Page 1
– Sub 2
- Main 2
So when i’m on page “Page 1″ i need to get “Sub 1″ and “Sub 2″ listed.
I read the docs about wp_list_pages and found nothing… searched for plugins, nothing…
Any ideas?
I think a great plug-in would be one that we could choose what level of the menu we want to display… that would be mind blowing for Wordpress use as a cms : )))
Cam
June 19th, 2007 at 8:39 am
This plugin has a function called collapsing_page_menu_get_current_parents. You can use that to get an array of all of a page’s ancestors.
Good luck!
Scot Hacker
July 11th, 2007 at 9:13 am
With version 1.1 and WP 2.2.1 I’m seeing the behavior mentioned above - sub-menus only appear if you’re currently viewing that section of the site. Can I tweak this plugin so that submenus appear while viewing any part of the site? Thanks.
Cam
July 11th, 2007 at 10:02 am
Scot: That is in fact the whole point of this plugin. If you want submenus to appear on every page, you should use wp_list_pages–this plugin “collapses” sub-menus so they only show when their parent is selected.
Scot Hacker
July 12th, 2007 at 12:46 am
Well, you learn something new every day. You’re right - wp_list_pages() gets me exactly what I need. You might want to make the difference a bit more clear in this plugin’s description, for those of us newbies who think we need a plugin even we don’t. Thanks!
Michal
July 12th, 2007 at 8:12 am
I’m happy I’ve found your plug-in. But is there an easy way to display all hierarchy except the top one? just submenus of all levels? probably collapsing_page_menu_get_current_parents function would be useful here but I am not a PHP guy unfortunately… Cheers!
port
July 18th, 2007 at 1:39 pm
it displays drafts and private pages
Jessib said they could be removed by adding a line to make sure the post_status is ‘publish’ in the database call, in the collapsing_page_menu function.
Can someone explain what this should say? I need to get rid of private pages asap!
Thanks!
Cam
July 19th, 2007 at 9:29 am
port: I’ve uploaded a fixed version. Click the download link again.
Alternatively, add the following line beneath line 48:
Tiram
July 21st, 2007 at 3:41 am
I was glad when I found your plug-in, but it doesn’t seem to work for me.
The way I understand your instructions and the comments in this thread, a should get a menu with expanding sub-pages automatically when I include this bit of PHP in sidebar.php:
The menu does appear, but I only get the top-level pages, even when I click on page that have sub-pages. To illustrate:
http://tiram.org/blogg/
In the sidebar on my blog, under “Menytest 1″, you can see the top-level pages. The page named “Snarveier” has three sub-pages, on two levels, but they don’t appear when I click on that page, as I expected:
http://tiram.org/blogg/links/
The pages in the menu headed “Menytest 1″ are structured like this:
2006
Handleliste
Snarveier
- Bildegalleri
- tags
- Lenketestside
Galleri
What I’d like to see, is on the home page:
2006
Handleliste
Snarveier
Galleri
And when I click on “Snarveier”:
2006
Handleliste
Snarveier
- Bildegalleri
- Lenketestside
Galleri
And when I click on “Bildegalleri”:
2006
Handleliste
Snarveier
- Bildegalleri
- tags
- Lenketestside
Galleri
Shouldn’t that be possible using this plug-in?
Tiram
July 21st, 2007 at 3:44 am
Ow, sorry for posting again, but I see I need to post the sub-pages to “Snarveier” again - they should be:
Snarveier
- Bildegalleri
- - tags
- Lenketestside
David Szpunar
July 23rd, 2007 at 3:05 pm
This plugin appears to be just what I was looking for! I just downloaded it to start playing, and so far it’s working great when I call it using this code (from a Widgetize Anything widget, fancy way of getting non-widget to sidebar!):
global $post;
global $wpdb;
$parent_1 = $wpdb->get_var(”SELECT post_parent FROM $wpdb->posts WHERE ID=’$post->ID’”);
$parent_2 = $wpdb->get_var(”SELECT post_parent FROM $wpdb->posts WHERE ID=’$parent_1′”);
$parent_3 = $wpdb->get_var(”SELECT post_parent FROM $wpdb->posts WHERE ID=’$parent_2′”);
if($parent_1 == 0) {$root=$post->ID; $current=$post->ID;}
if($parent_1 != 0 && $parent_2 == 0 && $parent_3 == 0) {$root=$parent_1; $current=$post->ID;}
if($parent_1 != 0 && $parent_2 != 0 && $parent_3 == 0) {$root=$parent_2; $current=$post->ID;}
if($parent_1 != 0 && $parent_2 != 0 && $parent_3 != 0) {$root=$parent_3; $current=$post->ID;}
//Debug output
echo “parent_1: “.$parent_1.”parent_2: “.$parent_2.”parent_3: “.$parent_3.”current: “.$current.”";
echo collapsing_page_menu($root, ‘menu_order’, ‘ASC’, ’subpage_item’, ‘current_subpage_item’, $current);
It’s not pretty, I’m just testing to see if it works. Basically I have a tab bar across the top with my top-level pages. On the sidebar, I always want to see my level 2 pages. Under the currently-selected level 2 page (but no others), I want to see the level 3 pages. And so on, with three or four pages deep probably plenty. I only want the currently selected page, at whatever level, to be highlighted (using the current_page_item style or some such). The rest I need to style identically, except each level of subpages needs to be indented (so each level having it’s own class or some such would be helpful).
Right now, when I use custom classes for the list items (subpage_item and current_subpage_item, as in the sample code above), only the ‘top level’ (root in your plugin, 2nd level pages for me) pages get the custom classes, while the subpages at lower levels get default page_item and current_page_item classes. Also, one item is getting current_subpage_item and then those below it are getting current_page_item class tags. That’s the non-custom version in the latter case, and the custom version in the former. But there are both…I just want the actual item to have the “current” class.
I what I want possible with your plugin in a way I’m not seeing, or can it be modified easily? I’m an old Perl scripter, out of practice and messing around with PHP a bit, so if I had how all the code worked in my head I could probably figure it out, but since I didn’t write it and I’m not terribly familiar with the WordPress internals, I’ve gotten lost in a few places…
Thanks in advance for any help!
steve
July 24th, 2007 at 8:54 pm
This is fantastic.
Is there a way to limit the depth of pages this functions on.
I want to have the first and second levels displayed, then on the one page it goes to a third level I want to list those sub pages in the main content area not in the menu.
I cant figure out how to stop them showing up in the menu.
Check it out at http://www.hopecentre.org.nz/hutt/?page_id=15
I want to remove the sub pages from the menu list.
Cheers,
Cam
July 26th, 2007 at 8:40 am
steve: you’d have to write an extension to the plugin that checks for depth. You could accomplish it using a static variable that you increment with each call to the function (it’s recursive).
stuart g
August 8th, 2007 at 1:48 pm
Here is how I used this nifty plugin, thanks!
in file /wp-includes/widgets.php about line 330 find this block of code:
extract( $args );
$options = get_option( ‘widget_pages’ );
$title = empty( $options[’title’] ) ? __( ‘Pages’ ) : $options[’title’];
$sortby = empty( $options[’sortby’] ) ? ‘menu_order’ : $options[’sortby’];
$exclude = empty( $options[’exclude’] ) ? ” : ‘&exclude=’ . $options[’exclude’];
if ( $sortby == ‘menu_order’ ) {
$sortby = ‘menu_order, post_title’;
}
$out = wp_list_pages( ‘title_li=&echo=0&sort_column=’ . $sortby . $exclude );
if ( !empty( $out ) ) {
?>
Geoffrey Hughes
August 13th, 2007 at 9:53 pm
Great plugin but it would be nice if it supported Garrett Murphey’s Page Link Manager plugin for the exclusion of pages in the navigation.
Cam
August 14th, 2007 at 6:42 am
It would be nice if Garrett Murphey’s plugin supported *mine*.
Geoffrey Hughes
August 14th, 2007 at 7:57 pm
I’ve added 3 lines to your plugin to make it compatible.
pro01
August 29th, 2007 at 4:49 am
unfortunately it does not work on my end as it should. i am using WP 2.2.2 and all i can really get out of the plugin is list of the parents. my menu is three levels deep and at any time i can only see the topmost level. if i change the root_id, i can switch to the next level, but the children are still not shown when their parent is clicked. the plugin does not apply the css_li_selected class on the currently active item either. and does not change the default preset css_li class. the latter is something i can easily bypass, so it does not bother me at all, but i guess it’s something worth mentioning.
i would gladly accept any ideas on how the hidden children and not applying active class problems can be solved.
the menu call is in my page template and I use different page templates for the two language versions of the site (if that does make any difference).
Brian
August 30th, 2007 at 12:59 pm
Geoffrey - Could you share with us how you made this plugin compatible with the Garrett Murphey one?
Cam- Could you explain how one would go about adding depth limit to your plugin?
gee
August 31st, 2007 at 12:24 am
does anyone have a sample of their code + url that i can look at . i don’t know php well at all and am having trouble figuring this out (the USE directions above still leave me scratching my head). can’t seem to hook into the css AND can’t get the default wp child link to disappear (i can get this plugins link to expand and collapse, but not the default, if that makes any sense).
cheers!
Bildschirmschoner
August 31st, 2007 at 2:25 am
Muchas Gracias por tu trabajo Señor! Pero lastimostamente no puedo usar.
James Scott
September 20th, 2007 at 5:10 am
“Nate
February 20th, 2007 at 12:48 pm
Hmm…has anyone got this working for 2.1 yet? I made all the changes listed above, but all I get is an error after uploading and activating this plugin”
As per Nate’s post above, I get the following error:
Parse error: parse error, unexpected T_VARIABLE in […]/james-scott.co.uk/wp-content/plugins/collapsing_page_menu.php on line 41
…when I make the following change:
”
Changing this:
$pages = $wpdb->get_results(â€SELECT * †.
“FROM $wpdb->posts †.
“WHERE post_status = ’static’ AND †.
“post_parent=$root_id †.
“ORDER BY $order_by $order_dirâ€);
to this:
$pages = $wpdb->get_results(â€SELECT * †.
“FROM $wpdb->posts †.
“WHERE post_status = ‘publish’ AND post_type = ‘page’ AND †.
“post_parent=$root_id †.
“ORDER BY $order_by $order_dirâ€);
”
When I do not make any changes, I just get a listing of my parent pages, with no subpages.
I googled the T_VARIABLE error and found that it’s a general error related to syntax issues, so I reopened the file after editing it (note that you can’t open it in the wordpress plugin editor because when the parse error occurs it takes down the whole site). What had actually happened is that all of the single and double quotes had been replaced by garbage. I replaced this with quotes (in a plain text unix compatible text editor, in my case the one provided with most hosting packages). My website came back up, but only with the original list of parent pages (no children).
Looking at the code a bit more, I realised that the changes appear to be already built in to the plugin (thanks Cam) and the old code is just for backward compatibility. Therefore I have redownloaded and reinserted the plugin without any changes, but I still didn’t get the child pages. On printing the value of the $version variable in the plugin, I found that I’m actually using version 2.0.1 of wordpress (I thought I had 2.1).
Ok, so with all of that out of the way, I thought that maybe an upgrade to the latest version (2.2.3 at time of writing) might work, because I didn’t know where to begin to work out why the plugin wasn’t working correctly on my version. I upgraded, and now everything works great!
In short, if you have an older version for which the children pages are not showing, (e.g. version 2.0.1) just upgrade your version of wordpress. It’s pretty painless and the plugin is more likely to work.
Niels
September 26th, 2007 at 10:46 am
Hello,
I am using the Tiga theme and I am having severe problems with this plugin but then again I have no experience with this sort of stuff. I do not know how well code can be posted here so I will go with a screen shot. I assume this is where I need to do the edit. How should this look?
http://img210.imageshack.us/img210/9242/sidebarmb9.jpg
Help would be greatly appriciated
Stefano
October 10th, 2007 at 4:46 pm
Geoffrey Hughes could you share with us how you made this plugin compatible with the Garrett Murphey one?
Steve
October 17th, 2007 at 1:31 am
Im using this plugin want want to hide a page from showing up in the menu.
I know using wp_list_pages() I can set page id’s to exclude from the menu.
Is there anyway to do it using this plugin?
Thanks
Peet Morgan
October 17th, 2007 at 2:42 am
To all those looking for a way to exclude pages there is a hack -
It can be done manually in the SQL statement within the plugin (around line 50 for version 1.2). You can put in an ID exclusion into the where statement for each page id you don’t want to appear. Like so:
“ID 28 AND ” . // addition to exclude page
“ID 35 AND ” . // addition to exclude page
Thanks Cam for you hard work - sorry to be suggestion hacks for such a fine plugin.
Brian
October 28th, 2007 at 4:56 am
Hi Cam,
Great plug-in. Great way to help many make wp more cms like.
I read all on this page and tried to insert the code many places, but it doesn’t work
I am trying to use cutline 1.1 split on a new site. I have wp 2.2.3 installed.
The left sidebar code looks like this:
Categories
Archives
Admin
WordPress
XHTML
Any help inserting the code will be much appreciated!
Best regards,
Brian
Sachin Sagar
November 2nd, 2007 at 4:26 am
This plugin rocks.
But it would be much better if you could add one more parameter ‘exclude=x’ to exclude some selected menus.
Thanks.
John
November 15th, 2007 at 9:50 am
Tnx. Worked perfect.
8 » Blog Archive » Collapsing Pages plugin
May 15th, 2008 at 2:47 am
[…] This plugin does not work well for me in over 20 themes I’ve tried it in: http://sporkfancier.com/collapsing-page-menus-plugin […]
Leave a Reply