做所有主题开发前,一定要理解wordpress的工作流程。不用去管wordpress其他流程。只要理解插件和主题的工作流程就好。wordpress打开网站,首先会读取主题的style.css,这个无需加载在functions.php, 然后wordpress会读取index.php, 然后会读取functions.php /。 wordpress自定义了数十种默认的查询和模板,上百种自带的函数,具体可以去看wordpress hierarchy 那个图。
所以一切的一切,都是从functions.php开始的。所有文件都是从这里开始导入的,用require或者inluce导入。当然index.php里面导入也可以的。比方说get_headr()之类的函数,也是在导入模板。
首先我们看这个主题框架的framework. 分好几类,一个文件套一个文件,从而构成了 后台管理页面设置的字段、post mketa、 term meta\、 shortcode 、widgets、自定义blocks 等等的环节。
我们先查看sahifa主题的functions.php 文件。 首先他定义的是一些必要的常量。这个跟其他地方调用的关系很大,如果这里没定义,其他地方就搜索不到这个常量,就会显示错误。
define ('THEME_NAME', 'Sahifa' );
define ('THEME_FOLDER', 'sahifa' );
define ('THEME_VER', '5.7.6' ); //DB Theme Version
define( 'NOTIFIER_XML_FILE', "http://themes.tielabs.com/xml/".THEME_FOLDER.".xml" );
define( 'NOTIFIER_CHANGELOG_URL', "http://tielabs.com/changelogs/?id=2819356" );
define( 'DOCUMENTATION_URL', "http://themes.tielabs.com/docs/".THEME_FOLDER );
if ( ! isset( $content_width ) ) $content_width = 618;
然后通过引用一系列函数文件,来实现结构整齐和分类。
// Main Functions
require_once ( get_template_directory() . '/framework/functions/theme-functions.php');
require_once ( get_template_directory() . '/framework/functions/common-scripts.php' );
require_once ( get_template_directory() . '/framework/functions/mega-menus.php' );
require_once ( get_template_directory() . '/framework/functions/pagenavi.php' );
require_once ( get_template_directory() . '/framework/functions/breadcrumbs.php' );
require_once ( get_template_directory() . '/framework/functions/tie-views.php' );
require_once ( get_template_directory() . '/framework/functions/translation.php' );
require_once ( get_template_directory() . '/framework/widgets.php' );
require_once ( get_template_directory() . '/framework/admin/framework-admin.php' );
require_once ( get_template_directory() . '/framework/shortcodes/shortcodes.php' );
if( tie_get_option( 'live_search' ) )
require_once ( get_template_directory() . '/framework/functions/search-live.php');
if( !tie_get_option( 'disable_arqam_lite' ) )
require_once ( get_template_directory() . '/framework/functions/arqam-lite.php');
Theme function文件存储的是跟主题相关的函数文件。
ha_options_build( $value, $option_name, $data )是构建字段Html之input输入框的。文件在framework-options.php里面。
先通过framework-panel.php文件里的ha_add_admin()函数来添加管理设置页面,