【发布时间】:2012-04-02 14:50:18
【问题描述】:
我的网站有博客功能要求。我必须制作与我的网站外观相同的博客。
如何结合 CodeIgniter 和 Wordpress 博客(仅限)功能,使其看起来像在同一个网站中?
我看过这个问题:Wordpress template with codeigniter。但没有太多线索。
【问题讨论】:
标签: php wordpress codeigniter integration blogs
我的网站有博客功能要求。我必须制作与我的网站外观相同的博客。
如何结合 CodeIgniter 和 Wordpress 博客(仅限)功能,使其看起来像在同一个网站中?
我看过这个问题:Wordpress template with codeigniter。但没有太多线索。
【问题讨论】:
标签: php wordpress codeigniter integration blogs
似乎有点矫枉过正。
为什么不使用像 json_api 这样的 Restful 服务来检索您的帖子,然后复制 css 文件(部分)?
【讨论】:
您将需要创建 2 个文件并修改 2 个现有函数。一个函数在 CodeIgniter 中,另一个在 Wordpress 中。
这里是步骤。
1.) 打开您的 configs/hooks.php 文件并创建一个 pre_controller 挂钩,如下所示:
$hook['pre_controller'] = array(
'class' => '',
'function' => 'wp_init',
'filename' => 'wordpress_helper.php',
'filepath' => 'helpers'
);
2.) 在你的 helpers 目录中创建一个名为 'wordpress_helper.php' 的新文件,并在其中添加以下代码:
/**
*
*/
function wp_init(){
$CI =& get_instance();
$do_blog = TRUE; // this can be a function call to determine whether to load CI or WP
/* here we check whether to do the blog and also we make sure this is a
front-end index call so it does not interfere with other CI modules.
*/
if($do_blog
&& ($CI->router->class == "index" && $CI->router->method == "index")
)
{
// these Wordpress variables need to be globalized because this is a function here eh!
global $post, $q_config, $wp;
global $wp_rewrite, $wp_query, $wp_the_query;
global $allowedentitynames;
global $qs_openssl_functions_used; // this one is needed for qtranslate
// this can be used to help run CI code within Wordpress.
define("CIWORDPRESSED", TRUE);
require_once './wp-load.php';
define('WP_USE_THEMES', true);
// Loads the WordPress Environment and Template
require('./wp-blog-header.php');
// were done. No need to load any more CI stuff.
die();
}
}
3.) 打开 wp-includes/link-template.php 并进行以下编辑:
if ( ! function_exists('site_url'))
{
function site_url( $path = '', $scheme = null ) {
return get_site_url( null, $path, $scheme );
}
}
4.) 将 CodeIgniter 帮助文件夹中的 url_helper.php 复制到您的 APPPATH 帮助文件夹 并进行以下编辑:
if ( ! function_exists('site_url'))
{
function site_url($uri = '', $scheme = null)
{
// if we are in wordpress mode, do the wordpress thingy
if(defined('CIWORDPRESSED') && CIWORDPRESSED){
return get_site_url( null, $path, $scheme );
}else{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
}
}
上述步骤将允许您基于一些简单的过滤动态加载您的 CI 应用程序或 WP 站点。它还使您可以访问 WP 中的所有 CI 功能,这是您可以使用的。
【讨论】: