PHP头条
热点:

编写PHP脚本使WordPress的主题支持Widget侧边栏


帮网友小改了一下主题. 任务比较简单, 只是为一个三栏主题添加对 Widget 的支持而已,就先从这次简单的案例开始说吧.

20151214152214148.png (600×360)

单侧边栏

functions.php

 <&#63;php if( function_exists('register_sidebar') ) { register_sidebar(array( 'before_widget' => '
  • ', // widget 的开始标签 'after_widget' => '
  • ', // widget 的结束标签 'before_title' => '

    ', // 标题的开始标签 'after_title' => '

    ' // 标题的结束标签 )); } &#63;>

    sidebar.php

      
      <&#63;php // 如果没有使用 Widget 才显示以下内容, 否则会显示 Widget 定义的内容 if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : &#63;>
    • 标题 1

      • 条目 1.1
      • 条目 1.2
      • 条目 1.3
    • 标题 2

      • 条目 2.1
      • 条目 2.2
      • 条目 2.3
    • <&#63;php endif; &#63;>

    双侧边栏

    functions.php

     <&#63;php if( function_exists('register_sidebar') ) { register_sidebar(array( 'name' => 'Sidebar_1', // 侧边栏 1 的名称 'before_widget' => '
  • ', // widget 的开始标签 'after_widget' => '
  • ', // widget 的结束标签 'before_title' => '

    ', // 标题的开始标签 'after_title' => '

    ' // 标题的结束标签 )); register_sidebar(array( 'name' => 'Sidebar_2', // 侧边栏 2 的名称 'before_widget' => '
  • ', // widget 的开始标签 'after_widget' => '
  • ', // widget 的结束标签 'before_title' => '

    ', // 标题的开始标签 'after_title' => '

    ' // 标题的结束标签 )); } &#63;>

    sidebar.php

      
      <&#63;php // 如果没有在侧边栏 1 中使用 Widget 才显示以下内容, 否则会显示 Widget 定义的内容 if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar_1') ) : &#63;>
    • 标题 1

      • 条目 1.1
      • 条目 1.2
      • 条目 1.3
    • <&#63;php endif; &#63;>

      
      <&#63;php // 如果没有在侧边栏 2 中使用 Widget 才显示以下内容, 否则会显示 Widget 定义的内容 if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar_2') ) : &#63;>
    • 标题 2

      • 条目 2.1
      • 条目 2.2
      • 条目 2.3
    • <&#63;php endif; &#63;>

    N 侧边栏
    请使用数学归纳法进行推理XD

    内容推荐:免费高清PNG素材下载

    www.phpzy.comtrue/phpzx/46795.htmlTechArticle编写PHP脚本使WordPress的主题支持Widget侧边栏 帮网友小改了一下主题. 任务比较简单, 只是为一个三栏主题添加对 Widget 的支持而已,就先从这次简单的案例开始说吧. 单侧边栏 functions.php...

    相关文章

    PHP之友评论

    今天推荐