如何整合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. 如何将Cometchat与Wordpress整合
- 3. 如何整合phpBB与Wordpress
- 4. 整合phpgrid与codeigniter
- 5. 如何最好地将移动服务与CodeIgniter整合?
- 6. 如何将Wordpress整合到Kohana 3中
- 7. CodeIgniter中的模板系统像wordpress?
- 8. 如何将h2o模板引擎与codeigniter集成
- 9. 如何处理Codeigniter模板?
- 10. 如何将wordpress与现有的php主页整合?
- 11. 如何正确整合jQuery表与金字塔模板?
- 12. 如何整合Wordpress和bbPress?
- 13. codeigniter与wordpress
- 14. 如何将hebo html模板整合到yii框架中
- 15. 如何将Google触碰板与我的应用程序整合?
- 16. 如何合并模板与网站?
- 17. Codeigniter模板
- 18. CodeIgniter模板
- 19. CodeIgniter模板库
- 20. WordPress模板的整蛊菜单(HTML + CSS)
- 21. 将索引模板与动态模板结合起来
- 22. 将html模板与php代码混合:php html模板
- 23. 如何将payUmoney与opencart整合。
- 24. 你如何将CMock/Unity与Automake整合?
- 25. 如何将UIPATH与SVN整合?
- 26. 我如何将TortoiseSVN与netbeans6.8整合?
- 27. 如何将Flash与Php整合
- 28. 如何将ZF2与Doctrine Mongo ODM整合?
- 29. 如何将MSpec与MS Build整合?
- 30. 如何将贝宝与Zend Framework整合
它的工作原理absoultely完美感谢的人 – 2012-07-31 04:57:49