执行我认为您需要的一种方法是创建自定义模板文件,你可以放入任何主题。然后,您只需要通过wp-admin后端创建一个空的Wordpress页面,并将页面模板设置为“MyPluginPageTemplate”。模板页面与主题无关,可以放入系统中的任何或所有主题中。
例如,创建一个名为'myplugin-template.php'的文件并将其保存在活动主题文件夹的根目录中。 (例如/wordpress/wp-content/themes/activetheme/myplugin-template.php)
将下面的代码文件中:
<?
/**
* Template Name: MyPluginPageTemplate
*
* A custom page template for my plugin
*
* The "Template Name:" bit above allows this to be selectable
* from a dropdown menu on the edit page screen.
*
* @package WordPress
* @subpackage
* @since
*/
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php
$c = new MyPluginClass();
$c->pluginInit();
//Here follows the usual code to include page content in Wordpress - comment out here, because probably not required:
//get_template_part('loop', 'index');
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_footer(); ?>
在这个例子中我使用被包含一个插件在一个类中,但它可能只是一个像myplugin_init()这样的直接函数。
谢谢!我会试试这个。 – Dagligleder