标签: 自定义侧边栏

  • WP页面加入自定义侧边栏

            在前面一篇文章中简要介绍了如何创建wordpress自定义页面,在此,介绍一下在自定义页面中加入个性化的侧边栏(sidebar.php),顶部(header.php)及底部(footer.php)。关于如何创建自定义页面,可参考此文:自定义WordPress的页面模板
    下面以侧边栏为例:

    我们知道在page.php(页面模板),single.php(文章模板),调用头部侧边底部的方法分别是:get_header(),get_sidebar(),get_footer(),在get_sidebar()方法中,有一段代码:

    function get_sidebar( $name = null ) {
    do_action( ‘get_sidebar’, $name );
    $templates = array();
    if ( isset($name) )
    $templates[] = “sidebar-{$name}.php”;
    $templates[] = “sidebar.php”;

    ……

    所以,我们只需要建一个以sidebar.php为母版的个性化sidebar-{YourName}.php文件,在页面模板的调用中将默认get_sidebar()修改为get_sidebar(“YourName”)即可。

    同理你也可以按此方法,自定义自己的header.php,footer.php 。
    本站的一个搜索页面示例:点击浏览.