Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to call a sidebar into my header. I've switched to the new twenty twelve theme and created my own child theme. With this new theme I decided to keep things organised and together, so I put my widgets functions, stylesheet and two new sidebar templates (one for header and one for footer widgets) in one folder called pgwidgets.

This is the call i used in my header

<? if ( is_front_page() ) : ?>  
<?php get_sidebar( 'homepage' ) ; ?>
<?php endif ; ?>

This calls the sidebar-homepage.php file into my header from the themes' root directory. How do I change the get_sidebar( 'homepage' ) part to call the sidebar from the pgwidgets folderfolder (pgwidgets/sidebar-homepage.php)

share|improve this question
1  
You should follow the structure of WP file structure codex.wordpress.org/Theme_Development#Template_Files_List Going away from that is just making it more complex. –  Hoshts Apr 20 '13 at 15:25
add comment

1 Answer

up vote 1 down vote accepted

Impossible with get_sidebar().

From that function’s body:

function get_sidebar( $name = null ) {
    do_action( 'get_sidebar', $name );

    $templates = array();
    if ( isset($name) )
        $templates[] = "sidebar-{$name}.php";

    $templates[] = 'sidebar.php';

So if you pass a $name or any other custom value to the function, they will be set between two fixed strings.

You can use locate_template() instead:

locate_template( 'pgwidgets/sidebar-homepage.php', TRUE );
share|improve this answer
    
toscho, excellent!!! many thanks for your help, works like a charm –  Pieter Goosen Apr 20 '13 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.