TEMPLATEPATH
gives the path of the file.
Just use <?php get_sidebar( 'alt' ); ?>
and it’ll fetch the file, located in the same folder, with alt after the hyphen, ie, sidebar-alt.php.
Hi Joseph!
Thanks so much for replying.
Do you mean replace
<?php include(TEMPLATEPATH.”/sidebar-alt.php”);?>
with
<?php get_sidebar( ‘alt’ ); ?>
?
Because i tried that and it didn’t work….and i’ve got the right custom value as well.
please help!
What’s in the custom field?
sidebar and enc for my replacement sidebar called sidebar-enc
If the custom field only stores the string enc then
<?php $sidebar = get_post_meta($post->ID, "sidebar", true);
get_sidebar($sidebar);
?>
should work, else you’ll have to remove other parts of the string first.
that’s going back to my question, i’ve tried that and it didn’t work unfortunately.
i believe it’s because i have two sidebars, one is called sidebar, the second called sidebar-alt.
if i use
<?php $sidebar = get_post_meta($post->ID, “sidebar”, true);
get_sidebar($sidebar);
?>
then it just replaces my sidebar, not sidebar-alt…..
Hi,
In ‘WordPress 3’ we have a cute new function:
<? get_template_part('filename','which'); ?>
Just add your sidebar code into php files and call these, lets say you have default (sidebar 1), plus three new options, then just create sidebar-2.php, sidebar-3.php, sidebar-4.php and add your sidebar code.
Calling the sidebars:
Default
<?php get_sidebar(); ?>
Sidebar 2
<? get_template_part( 'sidebar', 2 ); ?>
Sidebar 3
<? get_template_part( 'sidebar', 3 ); ?>
Sidebar 4
<? get_template_part( 'sidebar', 4 ); ?>
I have a post about this for twenty ten, splitting the two sidebars into their own files, there is a download so you can look at the code.
HTH
David
hi everyone
thanks for your help but i found what i was looking for:
i used this code:
<?php if ( is_page(‘whatever your page is called’) ) { ?>
<?php include(TEMPLATEPATH.’/sidebar-enc.php’);?>
<?php } else { ?>
<?php include(TEMPLATEPATH.’/sidebar-alt.php’);?>
<?php } ?>
and it works wonderfully!