2009-08-10 13 views

cevap

30

İlk adım, CodeIgniter ve WordPress dosyalarını kendi dizinlerine taşımaktır.

Bundan sonra, CodeIgniter'ın index.php dosyanızın en üstünde aşağıdaki satırı koyun. WordPress'in kök dizinine işaret etmek için yolu wp-blog-header.php olarak değiştirin.

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

Ardından, görünümlerinizde içine aşağıdaki işlevleri kullanabilirsiniz:

<?php 
    get_header(); 
    get_sidebar(); 
    get_footer();  
?> 

Diğer yardımcı fonksiyonları da entegre tasarım size yardımcı olabilir WordPress belgelerinde bulunabilir.

+0

Absoultely mükemmel çalışıyor teşekkürler dostum –

14

Codeigniter'in index.php sayfasında wp-blog-header.php dosyasını eklediğimde, site_url() öğesinin hem codeigniter's URL helper hem de WordPress içinde tanımlanmış bir sorun var. WordPress dosyası bir HTTP yanıt başlığını 'HTTP/bulunamadı 1.0 404 Page' başlığına ekleyerek gibi

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"); 

Son hat eklenmesi gerekir: Aşağıdaki kodu kullanarak bu çözüldü.

Şimdi CodeIgntier içinde aramak için WordPress işlevlerini kullanmak güzel. kodunuzda kod ignitörün site_url işlevini kullanarak planlıyoruz veya varolan bir CI site ve RP'nin birleştirme yapıyoruz eğer

0

... Bu yararlı olabilir: Üstteki

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); 
} 

etkili bir bu CI içinde SITE_URL kullanmasını sağlar, böylece zaten projenize bağlantılar ve içerik bir ton ekledim eğer size yardımcı olabilir.

4

Burada, kodlayıcı projenizde WordPress şablonlarını kullanmanın başka bir yolu var. Bu benim için daha iyi çalışıyor, bu yüzden paylaşmak istedim. WordPress 3.3.1 ve Codeigniter 2.1 ile test edilmiştir.

Dizin Yapısı:

/ - WordPress 
/ci/ - codeigniter 

/ci/index.php (CI Endeksi dosyasının Üst) varsayılan CodeIgniter versiyonunu geçersiz kılarak site_url fonksiyonu çarpışma ile

$wp_did_header = true; 

if (defined('E_RECOVERABLE_ERROR')) 
    error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR); 
else 
    error_reporting(E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING); 

require_once("../wp-config.php"); 

Deal. Bunun yerine, 'u kullanmak için site_url() kod işaretçisinde kullandığınız herhangi bir yeri değiştirmeniz gerekecektir.

/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; 
} 

Artık CI projesinde şablonu çizmek için get_header() ve/veya get_footer() fonksiyonları WordPress kullanabilirsiniz.

2

Özel CI e-ticaret sitesinde makaleleri yönetmek için WordPress kullanıyorum. CI benim ana sitem.

CI index.php üstüne aşağıdaki kodu eklerken berbat olmak benim URL'ler olmadan benim CI denetleyicileri içinde Wordpress fonksiyonlarını kullanabilmek için kulüpler
/application (CI) 
/... (directories like javascript, stylesheets ...) 
/system (CI) 
/wordpress 
/.htaccess 
/index.php (CI) 

:

dizin yapısı şudur
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); 
} 

Ayrıca Jérôme Jaglale (http://jeromejaglale.com/doc/php/codeigniter_i18n) tarafından CI i18n kitaplığı kullanırken de çalışır.