WordPress.org

Forums

[resolved] Sidebar files in sub directory (6 posts)

  1. tee05
    Member
    Posted 2 years ago #

    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!

  2. Michael
    Forum Moderator
    Posted 2 years ago #

    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

  3. tee05
    Member
    Posted 2 years ago #

    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?

  4. Michael
    Forum Moderator
    Posted 2 years ago #

    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');

  5. tee05
    Member
    Posted 2 years ago #

    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.

  6. tee05
    Member
    Posted 2 years ago #

    get_template_part('sidebar/sidebar-home');

Topic Closed

This topic has been closed to new replies.

About this Topic