0
我正在構建我的第一個wordpress插件,似乎被卡在某些東西上。如何使用插件添加一個新的(空白)頁面到一個wordpress站點
我需要這個插件在被激活時使用與網站其他部分相同的樣式創建一個新頁面;以及向該鏈接添加可定製路徑(/這是路徑)。
我已經研究瞭如何做到這一點,並且已經得到了一個空白的PHP文件顯示...使用此代碼:
//Template fallback
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
global $wpdb;
$plugindir = dirname(__FILE__);
//A Simple Page
if ($wp->query_vars[ "pagename" ] == 'event-photo-uploadr') {
$templatefilename = 'custom-uplaodr-page.php';
if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
$return_template = TEMPLATEPATH . '/' . $templatefilename;
} else {
$return_template = $plugindir . '/themefiles/' . $templatefilename;
}
do_theme_redirect($return_template);
}
}
function do_theme_redirect($url) {
global $post, $wp_query;
if (have_posts()) {
include($url);
die();
} else {
$wp_query->is_404 = true;
}
}
什麼,我需要知道現在的問題是,我怎麼能取代這個.php文件與一個在我的插件文件夾中?我也想知道如何爲這個頁面創建一個自定義鏈接,因爲它只需要爲那些有鏈接的人隱藏頁面。
必須全部通過插件運行,並在停用插件時刪除。
我也想聽聽關於我的代碼的最佳實踐和改進的任何提示。謝謝!
這是題外話題,因爲它是「請求代碼」,請[請閱讀問題清單](http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist)。無論如何,它不清楚你想要什麼...我懷疑這是[像這樣](https://github.com/tommcfarlin/page-template-example/)。研究[wordpress.se]中的[**''**](http://wordpress.stackexchange.com/questions/tagged/plugin-development?sort=votes&pageSize=50)標記,在那裏有好的材料。 –
brasofilo