开发者

CMS: Automatically Adding Child Pages into Navigation / Sidebar

I am currently maintaining a section in one of our clients' website. It's fairly simple: one parent page and multiple child pages. The parent displays all the links to the child pages; and, once you are on one of the sub-pages, there will be a sidebar that lists all the links to the other (sibling) pages.

This actually requires frequent updates: the client wants to add a new child page some time to time. Thus, they'd need to (i) add a new link on the parent page, (ii) create a new child page, and (iii) add a new link to the sidebar.

I am sure this is a good candidate for using a CMS e.g. WordPress; however, not too sure whether it'd be simpler. Specifically, is there a way in WordPress to accomplish (ii) and (iii) automatically? That is, to add a new child page and automatically have the sidebar added with that new child? Maybe a 开发者_如何学Pythonplugin?

If you have other suggestions about other CMS platform that is built more specifically for this purpose, I'd be very interested.


(ii, add new child page) is a default wordpress feature, so no problem there. (i and iii, dynamically create links/menus) is also no problem, if you know PHP basics and how to use the codexhttp://codex.wordpress.org/ (wordpress API doc).

Once you have created parent page and some sub-pages from within the wordpress admin page (a few clicks to do this), you need to either find a theme that shows the links in the sidebar by default, or simply modify a theme that you like but doesn't provide that feature. Modifying isn't tough in this case: you're looking for the wp_list_pages() function (see API doc). pass this function the argument 'child_of' = get_the_ID() and it will echo a link-list of the sub pages of the current page. This code can be placed anywhere within the main wordpress loop - just find the part of your theme that draws the sidebar (in twentyeleven, the default wordpress theme, I believe it's sidebar.php)

From my personal experience I can say that wordpress can be a mighty CMS even with slight modifications only. It's very easy to work with since the code is excellently structured and documented, so hacking it is pure joy.

If you dive deep into WP-core-code and not only theme-modification (the latter would suffice for your described purpose) I suggest you wrap all your modifications in a plugin so you don't overwrite them when updating WP.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜