Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress custom template, custom sidebar?

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #24500
    cjk
    Member

    Hey all,

    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?

    Best regards,
    Chris

    #55839
    apostrophe
    Participant

    Just create your custom sidebar/header and save it as sidebar2.php/header2.php or something equally imaginative and the call it/them in your custom template with

    Code:

    #55931
    cjk
    Member

    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?

    Cheers!
    Chris

    #55932
    apostrophe
    Participant

    That’s right. get_header and get_sidebar are just WordPress specific functions relating to the sidebar and the header. Just place the includes where you would usually use the WP functions.

    #55989
    cjk
    Member

    Hey,

    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;

    Quote:
    New way of adding sidebars

    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):

    Code:

    ‘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:

    Code:

    … regular html …

    … regular html …

    You can integrate your sidebars in your template-files (e.g. index.php, single.php, archives.php):

    Code:

    gets you the default sidebar.

    Code:

    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:

    Code:

  • ‘,
    ‘after_widget’ => ‘
  • ‘,
    ‘before_title’ => ‘

    ‘,
    ‘after_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

#55991
apostrophe
Participant

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

#56041
cjk
Member
"apostrophe" wrote:
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.

Cheers!
Chris

#64434
mlynn
Member

You could also simply use a plugin to create custom sidebars for each page or post. The Graceful Sidebar Plugin does this for you.

Viewing 8 posts - 1 through 8 (of 8 total)