options-framework 外掛下載 https://WordPress.org/plugins/options-framework/
一般放在當前主題下面。比如 yourtheme/includes/framework
然後在 function.php 呼叫它。
if ( !function_exists( 'optionsframework_init' ) ) {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/includes/framework/' );
require_once dirname(__FILE__).'/includes/framework/options-framework.php';
}
OPTIONS_FRAMEWORK_DIRECTORY 很重要,這個框架要用到的一個常量。
------------------
關於 options.php 這個檔案,可以從這裡得到:
https://github.com/devinsays/options-framework-theme
https://github.com/devinsays/options-framework-theme/archive/master.zip
在外掛的 includes/class-options-framework.php 有以下程式碼:
$location = apply_filters( 'options_framework_location', array( 'options.php' ) );
... locate_template( $location ) 這是用來載入 options.php 的。
後臺的主題選項編輯,主要是在 options.php 裡。
-------------
前臺得到值:類似: $logo_src = of_get_option( 'website_logo_upload', '' );
------
關於加入 js 程式碼: 因為後臺不能直接加入 js 程式碼,被認為不安全,那就透過下面程式碼的方式來新增:
add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');
function optionsframework_custom_scripts(){ ?>
<script type="text/javascript">
你的 js 程式碼
</script>
<?php
}