如何整合使用CodeIgniter WordPress模板
-
12-09-2019 - |
题
如何可以集成使得外观和感觉的/模板 WordPress的博客被携带到笨创建的网页?
解决方案
第一步是移动的CodeIgniter和WordPress的文件在自己的目录。
之后,把下面一行在你的CodeIgniter的index.php
文件的顶部。根据需要更改指向你的WordPress的根目录的路径,wp-blog-header.php
。
<?php
require('../wp-blog-header.php');
然后,您可以使用以下功能的意见里面:
<?php
get_header();
get_sidebar();
get_footer();
?>
其他辅助功能也WordPress的的文档中找到,其可以 帮助您设计集成。
其他提示
当我包括在该文件CodeIgniter的index.php页面可湿性粉剂博客 - header.php中,我得到了SITE_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功能CodeIgntier调用。
下面是另一种方式在你的笨项目中使用WordPress的模板。这对我的作品更好,所以我想分享它。测试与WordPress 3.3.1和笨2.1
目录结构:
/ - WordPress
/ci/ - codeigniter
/ci/index.php(顶CI Index文件的)
$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功能碰撞。你需要改变你使用site_url()
CI中使用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)
我能使用WordPress的功能在我的CI控制器,而我的网址添加以下代码到顶部时被弄乱了CI的的index.php
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);
}
使用CI I18N库由杰罗姆Jaglale( http://jeromejaglale.com/doc/php工作时也/ codeigniter_i18n )。
如果你在你的代码中使用的代码点火器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);
}
实际上,这可以让你用SITE_URL在CI,因此,如果您已经添加一吨的链接和内容到您的项目可能帮助你。