2015-03-19 48 views
1

我使用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; 
        } 
    } 
    

    https://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/wordpress_helper.php

    作者確實說了一個問題: 該版本的唯一問題是它始終呈現相同的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); 
        } 
        } 
    
    +0

    您使用的WP版本是什麼? – Und3rTow 2015-03-19 05:42:16

    +0

    @ M.Doye嗨。我正在使用WP 4.1.1 – xyonme 2015-03-19 05:45:20

    +0

    您可能需要使用require_once('path/to/wp-load.php')來交換'require_once dirname(__FILE__)。'/ blog/wp-blog-header.php';' ; ' – Und3rTow 2015-03-19 05:46:28

    回答

    0

    我在幫助文件笨的添加以下代碼看起來在配置中添加這個輔助/自動加載.php文件自動加載它。

    /** 
    * return CI header to home page cms for 
    */ 
    if (!function_exists('ci_header')) { 
    
        function ci_header() { 
         $CI = & get_instance(); 
         $header = $CI->load->view('includes/header.php', '', true); 
    
         return $header; 
        } 
    
    } 
    
    /** 
    * return CI footer to home page cms for 
    */ 
    if (!function_exists('ci_footer')) { 
    
        function ci_footer() { 
         $CI = & get_instance(); 
         $footer = $CI->load->view('includes/footer_homepage.php', '', true); 
    
         return $footer; 
        } 
    
    } 
    

    ,並在WordPress的wp-content把下面的代碼/主題/ my_theme/header.php文件

    <?php 
        echo ci_header(); 
    ?> 
    

    ,並在WordPress的wp-content把下面的代碼/主題/ my_theme/footer.php

    <?php 
    echo ci_footer(); 
    ?> 
    

    您可以在wordpress主題模板中直接使用任何幫助函數,因爲我在調用ci_header()和ci_footer();

    繼續...並總結我還有什麼需要爲您的項目做...

    +0

    中的內容我收到「調用未定義的函數」。我在codeigniter的「應用程序」之外安裝了wordpress文件夾「blog」。我還應該做什麼? – titolancreo 2015-06-12 06:43:58

    +0

    我有同樣的問題。你是如何解決你的問題的?運氣好的話 ? – MIIB 2015-06-12 13:32:07

    +0

    你有沒有在codeigniter中做過幫手,並且你是否自動加載,幫助在config/autoload.php中添加助手? – 2015-06-24 07:32:30