Support » Fixing WordPress » Sidebar files in sub directory

  • Resolved tee05

    (@tee05)


    Hi, I have a lot of custom sidebar files I’ll be creating for my theme. I would like to place the sidebar files in another folder called ‘sidebars’ to keep the files organized. I was wonder how can I retrieve the files when I call the function – get_sidebar(); ?

    For example this usually works: get_sidebar(‘home’);

    But since I have moved the file into a new folder it no longer works. I’ve tried: get_sidebar(sidebar/’home’); but it doesn’t work.

    Any help would be great, thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    consider using get_template_part() instead:

    http://codex.wordpress.org/Function_Reference/get_template_part

    example (depending on your folder structure and sidebar file names):

    get_template_part('sidebar/home')

    should call /wp-content/themes/yourtheme/sidebar/home.php

    Thanks for your response.

    I tried the code above but it did not work and also tried it in a number of combinations but still did not work.

    Any other suggestions?

    Michael

    (@alchymyth)

    Forum Moderator

    tried it in a number of combinations

    please post those combinations.

    what are your sidebar file names and which folder are they in?

    if it is ‘sidebar-home.php’ within a theme’s subfolder ‘sidebar’ then try:

    get_template_part('sidebar/sidebar-home');

    Thank you this time it worked!

    I think may have made a typo before (the folder name is ‘sidebars’ with an s at the end not ‘sidebar’).

    Thanks again for your help.

    get_template_part(‘sidebar/sidebar-home’);

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sidebar files in sub directory’ is closed to new replies.