【5.小工具】
對于共同使用的部分,如header.php,sidebar.php,footer.php,這時候不適合使用shortcode來解決在后臺更新,而使用小工具就是不錯的方案。
functions.php
~~~
//add our widget locations
function ourWidgetsInit(){
register_sidebar( array(
'name' => 'Sidebar',
'id' => 'sidebar1',
'before_widget' => '<div class="widget-item">',
'after_widget' => '</div>',
'before_title' => '<h4 class="my-special-class">',
'after_title' =>'</h4>'
));
register_sidebar( array(
'name' => 'Footer Area 1',
'id' => 'footer1'
));
register_sidebar( array(
'name' => 'Footer Area 2',
'id' => 'footer2'
));
register_sidebar( array(
'name' => 'Footer Area 3',
'id' => 'footer3'
));
register_sidebar( array(
'name' => 'Footer Area 4',
'id' => 'footer4'
));
}
add_action('widgets_init', 'ourWidgetsInit');
~~~
頁面顯示小工具:
footer.php
~~~
<!-- footer-widgets -->
<div class="footer-widgets">
<?php if (is_active_sidebar('footer1')) : ?>
<?php dynamic_sidebar('footer1'); ?>
<?php endif; ?>
<?php if (is_active_sidebar('footer2')) : ?>
<?php dynamic_sidebar('footer2'); ?>
<?php endif; ?>
<?php if (is_active_sidebar('footer3')) : ?>
<?php dynamic_sidebar('footer3'); ?>
<?php endif; ?>
<?php if (is_active_sidebar('footer4')) : ?>
<?php dynamic_sidebar('footer4'); ?>
<?php endif; ?>
</div><!-- /footer-widgets -->
~~~
`is_active_sidebar()`函數用來檢查側邊欄里是否有小工具,如果有則返回 True,沒有則返回 False。
- WordPress平臺的網站開發
- 電商主題開發
- WooCommerce主題開發優化部分
- 首頁開發
- WooCommerce
- 判斷用戶是否登錄
- WordPress Menu
- WooCommerce PayPal Checkout Gateway
- 頁面和文章
- 調用產品和文章
- 判斷屬于哪個頁面
- 相關文章
- 消除文章分享按鈕集底部的文字
- wordpress主題模板和主題開發
- wordpress主題準備
- wordpress主題文件結構
- 豪源主題
- WooCommerce SEO
- 插件開發
- wordpress二次開發
- theme基本顯示
- menu調用
- 分拆為header.php和footer.php
- 頁面、文章樣式選擇顯示
- 面包屑導航 Breadcrumb
- 特色圖
- 閱讀次數統計
- 分頁功能
- Advanced Custom Fields
- Custom Post Type UI
- post type
- 小工具
- 小工具調用
- shortcode
- 文章循環輸出
- 標題和文章限制字數輸出顯示
- WordPress主題theme1開發
- wordpress搭建多站點
- wordpress常用函數
- wordpress循環代碼
- Woocommerce
- Woocommerce支持
- WordPress插件開發
- wordpress會員插件
- WordPress插件使用
- WordPress插件集
- WordPress的核心
- Wordpress原理
- Wordpress要點
- WordPress網站搬家
- WPML
- 服務器
- Cloud 9
- test
- 網站