Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将WordPress模板与CodeIgniter集成_Php_Wordpress_Codeigniter_Wordpress Theming - Fatal编程技术网

Php 如何将WordPress模板与CodeIgniter集成

Php 如何将WordPress模板与CodeIgniter集成,php,wordpress,codeigniter,wordpress-theming,Php,Wordpress,Codeigniter,Wordpress Theming,如何集成CodeIgniter和WordPress,使 WordPress博客被转到CodeIgniter创建的页面?第一步是将CodeIgniter和WordPress文件移动到它们自己的目录中 在这之后,在CodeIgniter的index.php文件的顶部放置以下行。根据需要将路径更改为wp blog header.php,以指向WordPress的根目录 <?php require('../wp-blog-header.php'); WordPress的文档中还可以找

如何集成CodeIgniter和WordPress,使
WordPress博客被转到CodeIgniter创建的页面?

第一步是将CodeIgniter和WordPress文件移动到它们自己的目录中

在这之后,在CodeIgniter的
index.php
文件的顶部放置以下行。根据需要将路径更改为
wp blog header.php
,以指向WordPress的根目录

<?php
    require('../wp-blog-header.php');

WordPress的文档中还可以找到其他帮助函数,这些函数可以
帮助您集成设计。

当我将文件wp-blog-header.php包含在Codeigniter的index.php页面中时,我遇到了一个问题,即site_url()是在Codeigniter的url帮助程序和WordPress中定义的。我使用以下代码解决了这个问题:

require('blog/wp-blog-header.php');

add_filter('site_url', 'ci_site_url', 1);

function ci_site_url() {
    include(BASEPATH.'application/config/config.php');
    return $config['base_url'];
}

header("HTTP/1.0 200 OK");
最后一行需要添加,因为WordPress文件正在将HTTP响应头“HTTP/1.0 404页面未找到”添加到头中


现在可以使用WordPress函数调用CodeIgniter了。

如果您计划在代码中使用CodeIgnitor site\u url函数,或者如果您正在合并现有CI站点和WP。。。这可能会有帮助:

在CI index.php的顶部:

require_once '../wp-blog-header.php';

add_filter('site_url', 'ci_site_url', 4);

function ci_site_url($url, $path, $orig_scheme, $blog_id) {
    $CI =& get_instance();
    $new_path = str_replace("YOURSITEURLGOESHERE", "", $url);
    return  $CI->config->site_url($new_path);
}

实际上,这允许您在CI中使用站点url,因此,如果您已经在项目中添加了大量链接和内容,它可能会对您有所帮助。

以下是在codeigniter项目中使用WordPress模板的另一种方法。这对我来说更好,所以我想和大家分享。使用WordPress 3.3.1和Codeigniter 2.1进行测试

目录结构:

/ - WordPress
/ci/ - codeigniter
/ci/index.php(ci索引文件的顶部)

通过覆盖默认的codeigniter版本来处理site_url函数冲突。您需要将codeigniter中使用的
site\u url()
位置更改为使用
ci\u site\u url()

/ci/application/helpers/MY_url_helper.php

<?php
function anchor($uri = '', $title = '', $attributes = '')
{
    $title = (string) $title;

    if ( ! is_array($uri))
    {
        $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? ci_site_url($uri) : $uri;
    }
    else
    {
        $site_url = ci_site_url($uri);
    }

    if ($title == '')
    {
        $title = $site_url;
    }

    if ($attributes != '')
    {
        $attributes = _parse_attributes($attributes);
    }

    return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}


if ( ! function_exists('ci_site_url'))
{
    function ci_site_url($uri = '')
    {
        $CI =& get_instance();
        return $CI->config->site_url($uri);
    }
}

function current_url()
{
    $CI =& get_instance();
    return $CI->config->ci_site_url($CI->uri->uri_string());
}


function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{
    $title = (string) $title;

    $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? ci_site_url($uri) : $uri;

    if ($title == '')
    {
        $title = $site_url;
    }

    if ($attributes === FALSE)
    {
        return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";
    }

    if ( ! is_array($attributes))
    {
        $attributes = array();
    }

    foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
    {
        $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
        unset($attributes[$key]);
    }

    if ($attributes != '')
    {
        $attributes = _parse_attributes($attributes);
    }

    return "<a href='javascript:void(0);' onclick=\"window.open('".$site_url."', '_blank', '"._parse_attributes($atts, TRUE)."');\"$attributes>".$title."</a>";
}



function redirect($uri = '', $method = 'location', $http_response_code = 302)
{
    if ( ! preg_match('#^https?://#i', $uri))
    {
        $uri = ci_site_url($uri);
    }

    switch($method)
    {
        case 'refresh'  : header("Refresh:0;url=".$uri);
            break;
        default         : header("Location: ".$uri, TRUE, $http_response_code);
            break;
    }
    exit;
}

我正在使用Wordpress管理自定义CI电子商务网站中的文章。CI是我的主要网站。目录结构如下所示:

 /application (CI)
 /... (directories like javascript, stylesheets ...)
 /system (CI)
 /wordpress
 /.htaccess
 /index.php (CI)
在将以下代码添加到CI的index.php的顶部时,我能够在CI控制器中使用Wordpress函数,而不会弄乱URL:

require_once './wordpress/wp-blog-header.php';

add_filter('site_url', 'ci_site_url', 1);

function ci_site_url($uri = '') {
    $CI =& get_instance();
    $uri = ltrim(str_replace($CI->config->base_url('wordpress/'), '', $uri),'/'); // "wordpress/" is in my case the name of the directory where I installed Wordpress. See directory structure above.
    return $CI->config->site_url($uri);
}
使用Jérôme Jaglale()的CI i18n库时也可以使用

 /application (CI)
 /... (directories like javascript, stylesheets ...)
 /system (CI)
 /wordpress
 /.htaccess
 /index.php (CI)
require_once './wordpress/wp-blog-header.php';

add_filter('site_url', 'ci_site_url', 1);

function ci_site_url($uri = '') {
    $CI =& get_instance();
    $uri = ltrim(str_replace($CI->config->base_url('wordpress/'), '', $uri),'/'); // "wordpress/" is in my case the name of the directory where I installed Wordpress. See directory structure above.
    return $CI->config->site_url($uri);
}