第一步,安装yii和wp:


第二步,创建protected/components/ExceptionHandler.php文件

<?php
class ExceptionHandler
{
public function __construct()
{
define('YII_ENABLE_EXCEPTION_HANDLER',false);
set_exception_handler(array($this,'handleException'));
} public function handleException($exception)
{
// disable error capturing to avoid recursive errors
restore_error_handler();
restore_exception_handler(); $event=new CExceptionEvent($this,$exception);
if($exception instanceof CHttpException && $exception->statusCode == 404)
{
try
{
Yii::app()->runController("blog/index");
}
catch(Exception $e) {}
// if we throw an exception in WordPress on a 404, we can use
// our main error handler to handle the error
} if(!$event->handled)
{
Yii::app()->handleException($exception);
}
}
}
?>

第三步,把wp的目录移到yii中。。修改 yii 的入口文件 /xxx/website/index.php
这一步使得 yii 程序启动时加载 wordpress 的程序

<?php

define('WP_USE_THEMES', true);
$wp_did_header = true;
require_once('wordpress/wp-load.php');
 
require_once(dirname(__FILE__) . '/protected/components/ExceptionHandler.php');
$router = new ExceptionHandler(); // change the following paths if necessary
$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php'; // remove the following line when in production mode
// defined('YII_DEBUG') or define('YII_DEBUG',true); require_once($yii);
Yii::createWebApplication($config)->run();

第四步,在 yii 中运行 wordpress:protected/controllers/SiteController.php
修改里面的 actionIndex函数为

$this->layout = false; // note that we disable the layout
try {
//spl_autoload_unregister(array('YiiBase', 'autoload'));
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
//spl_autoload_register(array('YiiBase', 'autoload')); Yii::app()->end();
}
// if we threw an exception in a WordPress functions.php
// when we find a 404 header, we could use our main Yii
// error handler to handle the error, log as desired
// and then throw the exception on up the chain and
// let Yii handle things from here // without the above, WordPress becomes our 404 error
// handler for the entire Yii app
catch (Exception $e) {
throw $e;
}

好了,在浏览器中输入你的域名,一个整合在 yii 里的 wordpress 就呈现啦。


第五步,让 yii 的页面使用 wordpress 的主题:

如果希望你的网站统一用 wordpress 的主题,同时又想用 yii 来写页面,那么再做下面一个小修改就好了。
打开/protected/views/layouts/main.php 将里面的内容替换为

<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
// echos Yii content
echo $content;
?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

OK,大功告成。当然如果你对 yii 熟悉,这些 controller、layout 什么都可以随便搞。

转自http://www.shannap.com/yii-integrate-wordpress.html

yii和wp做博客的更多相关文章

  1. 解决“用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示”的问题记录(备忘)

    解决"用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示"的问题记录(备忘) 历时几个小时百度,终于靠自己理解解决了GitHub仓库图 ...

  2. 牛腩学ASP.NET CORE做博客(视频)

    牛腩学习ASP.NET CORE做的项目,边学边做. 目录: 01-dotnetcore网站部署到centos7系统上(时长 2:03:16) 02-前期准备及项目搭建 (时长:0:23:35) 03 ...

  3. 分享我做Dotnet9博客网站时积累的一些资料

    从2019年使用WordPress搭建Dotnet9网站,到现在手撸代码开发,介绍中间使用的一些资源,绝无保留,希望对大家有用. 1. 申请域名.搭建WordPress网站 时间点:2019年11月 ...

  4. yii2实战教程之新手入门指南-简单博客管理系统

    作者:白狼 出处:http://www.manks.top/document/easy_blog_manage_system.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文 ...

  5. 【五】将博客从jekyll迁移到了hexo

    本系列有五篇:分别是  [一]Ubuntu14.04+Jekyll+Github Pages搭建静态博客:主要是安装方面  [二]jekyll 的使用 :主要是jekyll的配置  [三]Markdo ...

  6. 2021年Wordpress博客搭建

    2021年WordPress博客搭建教程 这是一篇关于2021最新版的WP个人博客搭建教程.整篇文章会事无巨细的一步步讲述搭建博客的每一步. 0.前言 随着互联网和移动互联网的飞速发展,博客这一功能恍 ...

  7. 基于hexo+github搭建一个独立博客

    一直听说用hexo搭建一个拥有自己域名的博客是很酷炫的事情~,在这十一花上半个小时整个hexo博客岂不美哉. 使用Hexo吸引我的是,其简单优雅, 而且风格多变, 适合程序员搭建个人博客,而且支持多平 ...

  8. 前博客 http://bbs.landingbj.com/mytopic.jsp?action=mytopic&username=57071

    在工作学习的过程中,遇到了亮眼的技术点,或者 学习的心得体会,总想要记录下来,或是方便自己,或是帮助如同自己现在这般的新人.前人种树,后人乘凉.享受了前人留下的阴凉,也会考虑自己给后来者种下几棵树苗. ...

  9. 个人博客实现Archives查询小记

    这两天正在做博客,刚刚遇到一个问题,就是需要在主页实现文档分类功能,即通过日期将文章进行按日期进行分类. 比如这样的: 我个人的想法是,查询所有文章的日期,然后将日期进行格式化,只留下年份和月份,然后 ...

随机推荐

  1. asp.net—缓存

    1.页面缓存 要实现页面输出缓存,只要将一条 OutputCache 指令添加到页面即可. <%@ OutputCache CacheProfile=" " NoStore= ...

  2. 02快速学习ExtJs之---第一个HelloWord!

    这篇主要讲部署下ExtJS开发环境,以及搭建项目.我们使用ExtJs官方提供的Sencha Cmd来搭建 1.搭建项目 1.下载官方的Sencha Cmd工具,安装. 2..Window用户进入到命令 ...

  3. 高性能Java网络框架 MINA

    Apache MINA(Multipurpose Infrastructure for Network Applications) 是 Apache 组织一个较新的项目,它为开发高性能和高可用性的网络 ...

  4. mac 下载安装 IntelliJ IDEA Tomcat

    (1)Download IntelliJ IDEA https://www.jetbrains.com/idea/download/ (2)找了个激活码 http://www.oschina.net/ ...

  5. 移动端rem切图

    1.为什么用rem 根据屏幕大小,自动调整大小 2.如何使用rem 分以下几步 a.用ps把设置稿弄成640px或者750px的(记得等比例缩放) b.调试时记得把浏览器默认最小字体设置为最小.手机端 ...

  6. JavaScript判断是否是手机mobile登录

    在页面代码中加入以下js,即可利用JavaScript判断是否是手机mobile登录! <script type="text/javascript" src="${ ...

  7. js ajax简单使用

    文章部分资源来源:(http://blog.csdn.net/lzkkevin/article/details/6777474)以及(http://www.cnblogs.com/hwx0807/ar ...

  8. css选择器(E[att^=”val”]序号选择器)

    一.基本选择器序号 选择器 含义1. * 通用元素选择器,匹配任何元素2. E 标签选择器,匹配所有使用E标签的元素3. .info class选择器,匹配所有class属性中包含info的元素4. ...

  9. MySql 导出excel

    select * into outfile './bestlovesky.xls' from bestlovesky where 1 order by id desc  limit 0, 50;

  10. MySQL客户端Workbench

    MySQL客户端除了Navicat之外,还有官方推出的MySQL Workbench,能看到数据库包含的存储过程,而Navicate不能. 下载链接: 32位:http://cdn.mysql.com ...