笨和WordPress如何可以集成使得外观和感觉的WordPress博客被结转到笨创建的网页/模板?
Answer 1:
第一步是在自己的目录移动笨和WordPress的文件。
在此之后,把下面一行在你的CodeIgniter的顶部index.php
文件。 路径更改为wp-blog-header.php
根据需要指向你的WordPress的根目录。
<?php
require('../wp-blog-header.php');
然后,您可以使用以下功能的意见里面:
<?php
get_header();
get_sidebar();
get_footer();
?>
其他辅助功能也可以WordPress的文档,可以帮助您在设计中集成了中发现的。
Answer 2:
当我在文件中包含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打电话。
Answer 3:
这里是另一种方式在你的笨项目中使用WordPress的模板。 这对我的作品更好,所以我想分享它。 经测试与WordPress 3.3.1和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功能的碰撞处理。 你需要改变你使用的任何地方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项目。
Answer 4:
我使用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国际化库由杰罗姆Jaglale(当作品也http://jeromejaglale.com/doc/php/codeigniter_i18n )。
Answer 5:
如果你正在使用你的代码的代码点火器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,因此,如果您已经添加一吨的链接和内容到您的项目它可能会帮助你。