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
}