
WordPress Plugin: Sub Page FunctionsPlugin Name: Sub Page Functions I use WordPress throughout my site to organize content. In particular, I’ve found that WordPress “pages” are useful posting the short stories that I’ve written and that I’ve released under Creative Commons licenses. I wanted a particular sidebar to show up on the pages that are stories, and I immediately thought that if I made these stories a subpage of my “Published Stories” page, I could do that easily with a “is_subpage” conditional tag. Unfortunately, there is no such tag built in to WordPress. After experimenting with a few different ideas, I finally decided to create my own tags and create a plugin. “Sub Page Functions” is that plugin. About the PluginSub Page Functions introduces two new tags to use in WordPress templates. The first is a conditional tag which returns a boolean result; the second returns an object containing information about a subpage’s parent page. This plugin has been tested with WordPress versions 2.1 through 2.3, and should work with most other versions. rsc_is_subpage([$parent_page_id])This function determines whether the current page is a subpage or not. The parameter $parent_page_id is optional; if it is passed, then the function determines whether the current page is a subpage of the parent page with the given ID. Examples:
This simply prints the phrase “This is a subpage!” if the page displayed is indeed a subpage.
In my own site, I use this function to include a different sidebar for subpages of my “Published Stories” page:
rsc_get_parent()This function returns a $post object containing information about the current page’s parent page, if any. If there is no parent page, the function returns false. Example:
InstallationTo install this plugin, unzip the .zip file and upload the file sub_page_functions.php to the wp-content/plugins subdirectory of your WordPress installation. Then go to the Plugins page in your Admin screen, and activate the plugin there. That’s it! Print This Page
All original content on this site copyright ©1994 - 2009 by Richard S. Crawford. Unless noted otherwise, all content is protected by a
|