如何组合/集成CodeIgniter和Wordpress博客功能? [英] How to combine / integrate CodeIgniter and Wordpress blogs functionality?

查看:151
本文介绍了如何组合/集成CodeIgniter和Wordpress博客功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站具有博客的功能要求。

My website having feature requirement of blogging. I have to make blog which would look same like my website appearance.

如何组合CodeIgniter和Wordpress blogging(only)功能,使其在同一个网站中看起来像?

How to combine CodeIgniter and Wordpress blogging(only) functionality such that it should look like within same website?

我看到这个问题:带有codeigniter的Wordpress模板

推荐答案

您需要创建2个文件并修改2个现有函数。一个函数在CodeIgniter,另一个在Wordpress。

You do this you will need to create 2 files and modify 2 existing functions. One function is in CodeIgniter and the other is in Wordpress.

这里是步骤。

1。)打开configs / hooks.php文件并创建一个pre_controller hook如下:

1.) Open your configs/hooks.php file and create a pre_controller hook as follows:

$hook['pre_controller'] = array(
    'class'    => '',
    'function' => 'wp_init',
    'filename' => 'wordpress_helper.php',
    'filepath' => APPPATH.DS.'helpers'
);

2。)在helpers目录中创建一个名为wordpress_helper.php的新文件,以下代码:

2.) Create a new file in your helpers directory called 'wordpress_helper.php', and add the following code to it:



/**
*
*/
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并进行以下编辑:

3.) Open wp-includes/link-template.php and made the following edit:

if ( ! function_exists('site_url'))
{
    function site_url( $path = '', $scheme = null ) {
        return get_site_url( null, $path, $scheme );
    }

}

4)复制url_helper.php从CodeIgniter助手文件夹到您的APPPATH助手文件夹
并进行以下编辑:

4.) Copy url_helper.php from the CodeIgniter helper folder to your APPPATH helper folder and make the following edit:

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功能,这是您可以使用的。

The steps above will allow you to dynamically load either your CI app or your WP site based on some simple filtering. It also gives you access to all CI functionality within WP of that is something you can use.

这篇关于如何组合/集成CodeIgniter和Wordpress博客功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆