2013-02-04 38 views
2

我的使命:
我有一个系统可以是一个独立的网站,但我想成为现有CMS的一部分,这样我就可以避免编写自己的用户管理系统,论坛,博客系统等。我可以把它作为Joomla的组件!因为我之前一直在与之合作,但不幸的是我不喜欢Joomla!并因此选择了Wordpress。开发一个像Joomla组件一样的WordPress插件

我的问题:
我的系统都应该有我的Wordpress页面内的管理页面和前端页面。我已经能够创建一个插件并添加管理页面,但我还没有找到如何制作前端。 一种解决方案可能是在我选择的主题中创建一个页面模板,但是因为我想尽可能将Wordpress中的组件与我的组件分开,并且也希望它是独立于主题的,所以这是一个不好的解决方案。

你能帮到些什么:
请给我一个简单的例子,或者指导我使用一个教程或一个现有的Wordpress插件,以便我能够制作插件。请记住,此插件只能用于我的网页,并且我只想将Wordpress用作插件的外壳。

回答

1

执行我认为您需要的一种方法是创建自定义模板文件,你可以放入任何主题。然后,您只需要通过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()这样的直接函数。

+0

谢谢!我会试试这个。 – Dagligleder

相关问题