I have been playing with the custom template function in WordPress as I would like to use a special layout for a special section of pages.
I have figured out how to create a custom page.php file and assign it etc., however, I have not been able to find in the codex (or figure out even if it is possible) whether I can grab a custom header.php sidebar.php that would only appear in pages that use the custom template.
In a nutshell, I would like to use a different header and sidebar on pages that use the custom page template.
Is there a way?
Hey thanks Apostrophe,
I would have been surprised if there wasn’t a way to do this (seemed like a popular request for feature to me!) but couldn’t find it in the codex at all. You saved me a ton of time!
I am going to assume that I directly replace the get_header and get_sidebar with these include calls?
Close…. but not quite what I was hoping for. My sidebar.php is widget ready and so of course any widget that I have in the main sidebar shows up in any and all copies, if they are also widget ready (which i would really like if possible as there are some widgets I would like to use on certain pages only). I guess I could just strip the widget function out of those custom sidebars, but I would really like the functionality.
So, I dug into the codex one more time and found this page http://codex.wordpress.org/Customizing_Your_Sidebar where it explains how to;
You can register more than one sidebar. In wp-includes/widgets.php you find the function-definition for register-sidebars() which you may use in your custom function within your theme-folder (functions.php – if not existent, create an empty php-file by that name):
‘custom’ would mean you have to create a custom sidebar-file under the name sidebar-custom.php. Sidebars get indexed. Your default sidebar (sidebar.php) gets indexed as 1. Every succeeding one will have an index higher than 1. You will see your sidebars now listed in ‘Apearance’ -> ‘Widgets’.
In your sidebar-templates you may now call the dynamic generated content (widgets) by the index of your sidebars:
You can integrate your sidebars in your template-files (e.g. index.php, single.php, archives.php):
gets you the default sidebar.
should display your custom sidebar.
What I can’t figure out is where and how to put this code in my functions.php file. I am looking at the default functions.php for Kubrick. The first 8 lines are:
‘before_title’ => ‘
Which doesn’t exactly match up the code from the codex!
This is then followed by a lot of code which seems to be relevant only to the function for modifying the kubrick header image and background colours, which I don’t use.
I am thinking I can just delete everything after line 8, but am hesitant to do so!
Anyone able to guide me through this? What a great learning experience! :D
Funnily enough I saw this article today and thought of you http://wpcandy.com/articles/tutorials/how-to-make-the-most-out-of-your-sidebar.html
Thanks!! This post and link are extremely useful. I have it working nicely locally and "hopefully" all will go well when I upload to my site.
You must be logged in to reply to this topic.