zoukankan      html  css  js  c++  java
  • WordPress主题开发:开启侧边栏小工具功能

    步骤一:在主题的functions.php中,添加一段代码,开启侧边栏功能,代码如下:

    <?php 
    //参数
    $args = array(
        'name'          => __( '主侧边栏'),
        'id'            => 'sidebar-01',
        'description'   => '将在网页中显示的侧边栏',
            'class'         => '',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>' );
    //开启侧边栏函数
     register_sidebar( $args );     
     ?>

     如果需要多个工具栏,再复制一个就可以了

    步骤二:后台给侧边栏添加小工具

    步骤三:在模版文件中调用侧边栏

    <?php if ( is_active_sidebar( $index ) ) : ?>
         <?php dynamic_sidebar( $index ); ?>
    <?php else: ?>
        //提示用户
        //或者,显示一些默认的边栏效果
    <?php endif; ?>

    $index 指代哪个侧边栏,可以使用步骤一的name或id值识别

    is_active_sidebar( $index )

    判断侧边栏是否被集合,如果激活了,返回true,否则返回false。

    dynamic_sidebar( $index )
    此函数的做用,是调用$index指定的侧边栏。

    帮助文档:

    中文官方参考文档:http://codex.wordpress.org/zh-cn:%E4%B8%BB%E9%A2%98%E7%89%B9%E6%80%A7

    英文官方参考文档:http://codex.wordpress.org/Theme_Features

  • 相关阅读:
    关于input()
    HDU 3746
    HDU 4335 Contest 4
    HDU 4418 高斯消元法求概率DP
    HDU 4339 Contest 4
    HDU 4334 Contest 4
    HDU 4333 Contest 4
    HDU 4332 Contest 4
    HDU 4035
    HDU 4336
  • 原文地址:https://www.cnblogs.com/tinyphp/p/6360193.html
Copyright © 2011-2022 走看看