简体   繁体   中英

Would replacing <?php get_sidebar(); ?> with the 'get_template_part' cause any problems?

I know that the straightforward way of calling a Sidebar, within the WordPress Theme, is through the use of <?php get_sidebar(); ?> <?php get_sidebar(); ?> with the sidebar.php file being saved within the Theme's root.

In the interest of improved organisation, I have created a folder entitled 'Sidebars' and then within this folder, created a series of templates for each Sidebar.

I have then called these within the theme as follows:

<?php get_template_part( 'sidebars/sidebars-left-column' ); ?>

Can anyone tell me if whilst my approach works, if it would cause me any problems at a later date and as such, should stick with <?php get_sidebar(); ?> <?php get_sidebar(); ?>

You can absolutely use that. The get_sidebar() function is just more conventional. And it can be used to call specific sidebars for your template. ie : You've got these sidebars (as files) :

sidebar-blog.php, sidebar-home.php, sidebar-page.php, sidebar-with_a_lot_of_ads.php...

you can call them respectively with

get_sidebar('blog'), get_sidebar('home'), get_sidebar('page'), get_sidebar('with_a_lot_of_ads')...

But more important, if someone else has to maintain your code, it's better to use conventions...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM