如何整合CodeIgniter和WordPress,以使WordPress博客的外觀和風格/模板 轉移到CodeIgniter創建的頁面上?如何將WordPress模板與CodeIgniter整合
回答
第一步是將CodeIgniter和WordPress文件移動到他們自己的目錄中。
然後,在CodeIgniter的index.php
文件的頂部放置以下行。根據需要將路徑更改爲wp-blog-header.php
,以指向您的WordPress根目錄。
<?php
require('../wp-blog-header.php');
然後,您可以使用以下功能的意見裏面:
<?php
get_header();
get_sidebar();
get_footer();
?>
其他的輔助功能也可以WordPress的文檔,可以 幫助您在設計中集成了中發現的。
當我在Codeigniter的index.php頁面中包含wp-blog-header.php文件時,我遇到了一個問題,即codeigniter的URL助手和WordPress都定義了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");
最後行需要爲WordPress的文件被添加HTTP響應報頭「HTTP/1.0 404未找到網頁」到報頭被添加。
現在可以使用WordPress函數來調用CodeIgntier。
如果你打算在你的代碼中使用的代碼點火器SITE_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 SITE_URL,因此,如果您已經添加一噸的鏈接和內容到您的項目它可能會幫助你。
這是另一種在codeigniter項目中使用WordPress模板的方法。這對我更好,所以我想分享它。經過WordPress 3.3.1和Codeigniter 2.1的測試。
目錄結構:
/ - WordPress
/ci/ - codeigniter
/ci/index.php(頂CI指數文件)
$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");
處理通過重寫默認笨版本SITE_URL功能的碰撞。您需要更改您在codeigniter中使用site_url()
的任何地方,而不是使用ci_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;
}
您現在可以使用WordPress的get_header()
和/或get_footer()
功能繪製模板在你的CI項目。
我使用WordPress的在一個自定義的CI的電子商務網站管理的文章。 CI是我的主要網站。目錄結構如下:
/application (CI)
/... (directories like javascript, stylesheets ...)
/system (CI)
/wordpress
/.htaccess
/index.php (CI)
添加以下代碼CI的的index.php的頂部時,我能夠使用WordPress的功能在我的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);
}
使用JérômeJaglale使用CI i18n庫時也有效(http://jeromejaglale.com/doc/php/codeigniter_i18n)。
- 1. 如何在codeigniter中整合html模板?
- 2. CodeIgniter + Wordpress整合
- 3. 如何將Cometchat與Wordpress整合
- 4. 如何整合phpBB與Wordpress
- 5. 將WordPress與PayPal IPN整合
- 6. 整合phpgrid與codeigniter
- 7. 如何整合twitter bootstrap HTML CSS與codeigniter
- 8. 如何整合Intercom.io JS與WordPress和Typeform
- 9. 如何將模板集成到Codeigniter中?
- 10. 如何整合codeigniter和log4php?
- 11. 如何最好地將移動服務與CodeIgniter整合?
- 12. 如何將Magento整合到Wordpress中?
- 13. 如何將Wordpress整合到Kohana 3中
- 14. 如何將HTML頁面整合到WordPress?
- 15. 如何整合Sails.js與石膏板
- 16. 如何將h2o模板引擎與codeigniter集成
- 17. CodeIgniter中的模板系統像wordpress?
- 18. 如何處理Codeigniter模板?
- 19. 如何將wordpress與現有的php主頁整合?
- 20. 如何正確整合jQuery表與金字塔模板?
- 21. 如何整合MaterializeCss與Foundation 6 - Zurb模板?
- 22. 如何整合Wordpress和bbPress?
- 23. 如何整合jpreloader for wordpress
- 24. 如何將hebo html模板整合到yii框架中
- 25. 如何在與Codeigniter集成後訪問WordPress管理面板?
- 26. 如何將我的WordPress博客與Wordpress插件的新Facebook整合?
- 27. codeigniter與wordpress
- 28. 將CakePHP3整合Wordpress帖子
- 29. 如何將Google觸碰板與我的應用程序整合?
- 30. 與其他模塊CodeIgniter的模板(HMVC?)
它的工作原理absoultely完美感謝的人 – 2012-07-31 04:57:49