2009-08-10 20 views
41

के साथ वर्डप्रेस टेम्पलेट को एकीकृत करने के लिए कैसे करें कोडइग्निटर और वर्डप्रेस को एकीकृत किया जा सकता है कि का स्वरूप और अनुभव/टेम्पलेट वर्डप्रेस ब्लॉग कोडइग्निटर-निर्मित पृष्ठों पर ले जाया गया है?कोडइग्निटर

उत्तर

30

सबसे पहले कदम के लिए अपने स्वयं निर्देशिका में CodeIgniter और वर्डप्रेस फ़ाइलों को स्थानांतरित करने के लिए है।

उसके बाद, अपनी CodeIgniter के index.php फ़ाइल के शीर्ष पर निम्न लाइन डाल दिया। अपने वर्डप्रेस की रूट निर्देशिका को इंगित करने के लिए आवश्यकतानुसार wp-blog-header.php पर पथ बदलें।

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

उसके बाद, आप अपने विचार के अंदर निम्नलिखित कार्यों का उपयोग कर सकते हैं:

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

अन्य सहायक कार्य भी वर्डप्रेस के दस्तावेज़ जो डिजाइन को एकीकृत करने में सहायता कर सकते हैं में पाया जा सकता।

+0

यह बेहद सही धन्यवाद आदमी काम करता है –

14

जब मैंने कोडिनेटर के index.php पृष्ठ में फ़ाइल wp-blog-header.php फ़ाइल शामिल की, तो मुझे एक समस्या मिली है कि site_url() को कोडिनेटर के यूआरएल सहायक और वर्डप्रेस दोनों में परिभाषित किया गया है।

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

अंतिम पंक्ति वर्डप्रेस फ़ाइल के रूप में एक HTTP प्रतिक्रिया हेडर 'एचटीटीपी/1.0 404 पृष्ठ नहीं मिला' शीर्षक को जोड़ने था जोड़ना होगा: मैं निम्नलिखित कोड का उपयोग कर इस को हल किया।

अब कोडइग्निअर में कॉल करने के लिए वर्डप्रेस फ़ंक्शंस का उपयोग करने के लिए यह ठीक है।

0

अगर आप अपने कोड में कोड ignitor SITE_URL फ़ंक्शन का उपयोग करने की योजना बना रहे हैं, या आप एक मौजूदा सीआई साइट और WP के एक मर्ज कर रहे हैं ... यह उपयोगी हो सकता है:

शीर्ष पर

सीआई 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); 
} 

प्रभावी रूप से इस आप सीआई में SITE_URL उपयोग करने के लिए अनुमति देता है, तो यह आप बाहर मदद कर सकता है अगर आप पहले से ही अपनी परियोजना के लिए लिंक और सामग्री के एक टन जोड़ दिया है।

4

यहां आपके कोडिनेटर प्रोजेक्ट में वर्डप्रेस टेम्पलेट्स का उपयोग करने का एक और तरीका है। यह मेरे लिए बेहतर काम करता है इसलिए मैं इसे साझा करना चाहता था। वर्डप्रेस 3.3.1 और कोडिनेटर 2.1 के साथ परीक्षण किया गया।

निर्देशिका संरचना:

/ - WordPress 
/ci/ - codeigniter 

/ci/index.php (सीआई सूचकांक फ़ाइल का शीर्ष) डिफ़ॉल्ट CodeIgniter संस्करण अधिभावी द्वारा SITE_URL समारोह टक्कर के साथ

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

डील। ci_site_url() का उपयोग करने के लिए आपको कोडिनेटर में site_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; 
} 

अब आप अपने सीआई परियोजना में टेम्पलेट आकर्षित करने के लिए get_header() और/या get_footer() कार्यों वर्डप्रेस का उपयोग कर सकते हैं।

2

मैं एक कस्टम सीआई ई-कॉमर्स वेबसाइट में आलेखों के प्रबंधन के लिए वर्डप्रेस का उपयोग कर रहा हूं। सीआई मेरी मुख्य साइट है।

/application (CI) 
/... (directories like javascript, stylesheets ...) 
/system (CI) 
/wordpress 
/.htaccess 
/index.php (CI) 

मैं जब सीआई के index.php के शीर्ष करने के लिए निम्न कोड जोड़ने में गड़बड़ की जा रही मेरी यूआरएल के बिना मेरे सीआई नियंत्रकों में Wordpress कार्यों का उपयोग करने में सक्षम हूँ:

निर्देशिका संरचना निम्नलिखित है
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); 
} 

वर्क्स भी जब जेरोम Jaglale (http://jeromejaglale.com/doc/php/codeigniter_i18n) द्वारा सीआई i18n लाइब्रेरी का उपयोग कर।