我使用Wordpress的問題是希望將CodeIgniter功能合併到Wordpress主題文件中。例如,我在許多CodeIgniter視圖文件中都包含一個頁眉和頁腳。同樣的頁眉和頁腳也需要包含在Wordpress主題中。在Wordpress中加載CodeIgniter實例
這個想法是加載CI實例並在Wordpress上使用它。 任何幫助,將不勝感激!
我試過這個。
https://github.com/falexandrou/Codeigniter-Wordpress-Integration
文件路徑來加載CI引導是正確的了。 其結果是錯誤
Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php
站點步驟:
1.在下面的模板文件的頂部包含此:
- 404.php - index.php- archive.php- archives.php
- links.php -page.php - search.php - single.php */
<?php
$wp_ci['return'] = true;
require('codeigniter.php');
- 放笨文件沿模板目錄
這應該是加載CI實例,以便它可以在Wordpress中使用。
https://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/codeigniter.php
CI的index.php
<?php
$wp_did_header = true;
require_once dirname(__FILE__) .'/blog/wp-blog-header.php';
define('WP_USE_THEMES', true);
require_once BASEPATH.'core/CodeIgniter.php';
?>
UPDATE:
WP-博客頭
if (!isset($wp_did_header)) {
$wp_did_header = true;
require_once(dirname(__FILE__) . '/wp-load.php');
wp();
require_once(ABSPATH . WPINC . '/template-loader.php');
}
我成功加載WordPress的,但 所有的笨視圖我的ci_site_url fu nction返回website.com/blog/application
當它應該是website.com/application
我把這個代碼在WP主題之一index.php
define('STDIN', TRUE);
$_SERVER['argv'] = array();
ob_start();
require('../index.php');
$GLOBALS['wp_ci_output'] = ob_get_contents();
ob_end_clean();
$GLOBALS['CI'] = get_instance();
require_once(APPPATH.'helpers/wordpress_helper.php');
代碼參考:
http://thedaylightstudio.com/blog/2010/06/16/codeigniter-and-wordpress-integration
WordPress的-helper.php
/**
* Print codeigniter view file in wordpress content
*
* @access public
* @param string view file name
* @param array array of variables to be rendered
* @param boolean true to return, false to return
* @return mixed
*/
function wp_ci_load_view($view, $vars = array(), $return = FALSE){
extract($vars);
$file = APPPATH.'/views/'.$view.'.php';
$contents = file_get_contents($file);
//echo $contents;
$CI =& get_instance();
$check_funcs = array('ci_site_url(', '$this->');
$replace_funcs = array('site_url_wp_safe(', '$CI->');
$contents = str_replace($check_funcs, $replace_funcs, $contents);
$contents = eval('?>'.preg_replace("/;*\s*\?>/", "; ?>",
str_replace('<?=', '<?php echo ', $contents)).'<?php ');
if ($return === TRUE){
return $contents;
}
}
作者確實說了一個問題: 該版本的唯一問題是它始終呈現相同的CI頁面以獲取CI對象,並且無法操作它呈現的頁面。 謝謝。
MY_url_helper
function ci_site_url
:以不同CI SITE_URL和WP站點URL功能
if (! function_exists('ci_site_url')){
function ci_site_url($uri = '')
{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
}
您使用的WP版本是什麼? – Und3rTow 2015-03-19 05:42:16
@ M.Doye嗨。我正在使用WP 4.1.1 – xyonme 2015-03-19 05:45:20
您可能需要使用require_once('path/to/wp-load.php')來交換'require_once dirname(__FILE__)。'/ blog/wp-blog-header.php';' ; ' – Und3rTow 2015-03-19 05:46:28