duanque2413 2017-04-05 04:02
浏览 65
已采纳

将替换<?php get_sidebar(); 用'get_template_part'引起任何问题?

I know that the straightforward way of calling a Sidebar, within the WordPress Theme, is through the use of <?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(); ?>

  • 写回答

1条回答 默认 最新

  • duandan1995 2017-04-05 07:25
    关注

    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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?