wordPress開發-學習歷程(第一篇)

說明:這是個人在不斷學習中的理解感悟,若有不對之處,還請批評指正。

初步搭建的wordpress系統多少會滿足不了你的功能需求及樣式需求,這個時候可以通過安裝插件進行功能補充,安裝主題來進行版式佈局的修改,當然這種直接安裝第三方的方法,是不能滿足你的個性化需求的。這個時候就需要進行自己開發了。

這裏由於實際的開發,我先講解插件開發的流程

插件開發的好處就是講你的設計獨立於原來的wordpress的基本架構之外,這樣其實也更好與維護與管理。


管理後臺增加菜單:

add_action ( 'admin_menu', 'register_custom_menu_page' );
register_activation_hook(__FILE__,'report_install');//調用函數,插件激活時運行

function register_custom_menu_page() {
add_menu_page ( '報告', '報告', 'administrator', 'report', 'report_list', plugins_url ( 'myplugin/images/icon.png' ), 30 );
}

在插件激活時候執行某個函數

register_activation_hook(__FILE__,'report_install');//調用函數,插件激活時運行

function report_install () {
global $wpdb;

$table_name = $wpdb->prefix . "liveshoutbox";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {


$sql = "CREATE TABLE " . $table_name . " (
 id mediumint(9) NOT NULL AUTO_INCREMENT,
 time bigint(11) DEFAULT '0' NOT NULL,
 name tinytext NOT NULL,
 text text NOT NULL,
 url VARCHAR(55) NOT NULL,
 UNIQUE KEY id (id)
);";


require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章