Support » Themes and Templates » templatepath

  • Resolved 24lover

    (@24lover)


    hi everyone,
    i’m a newbie – can anyone tell me what templatepath is supposed to do? i’ve tried reading it up but nothing has helped (perhaps not enough layman terms).

    i’m basically trying to replace this:

    <?php include(TEMPLATEPATH.”/sidebar-alt.php”);?>

    with another sidebar. I know that usually you can just replace
    <?php get_sidebar(); ?>
    with
    <?php $sidebar = get_post_meta($post->ID, “sidebar”, true);
    get_sidebar($sidebar);
    ?>

    but since there’s the templatepath there, does anyone know how the code for that? or how to get around it?
    please help
    thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.

    Thread Starter 24lover

    (@24lover)

    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?

    Thread Starter 24lover

    (@24lover)

    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.

    Thread Starter 24lover

    (@24lover)

    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

    Thread Starter 24lover

    (@24lover)

    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!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘templatepath’ is closed to new replies.