我的网站有博客功能要求。我必须做博客,看起来和我的网站外观一样。
如何将CodeIgniter和Wordpress博客(仅)功能结合起来,使其看起来像在同一个网站中?
我看到了这个问题:Wordpress模板与代码点火器。但没有得到太多线索。
看起来有点过头了。
为什么不使用像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-includs/link-template.php并进行以下编辑:
if ( ! function_exists('site_url'))
{
function site_url( $path = '', $scheme = null ) {
return get_site_url( null, $path, $scheme );
}
}
4.)将url_helper.php从CodeIgniter助手文件夹复制到您的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功能,这是您可以使用的。