第一步,安装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. go学习与记录

    搭建go开发环境:http://studygolang.com/articles/5406 日志相关:https://github.com/hpcloud/tail go定时器:http://stud ...

  2. hibernate中get,load,list,iterate的用法及比较

    首先,get和load都是查询单个对象,而list和iterate为批量查询 注意以下写法仅针对hibernate3的语法. 使用案例如下: // 1. get和load 的用法 Person p = ...

  3. Ubuntu 14 安装Java(JRE、JDK)

    JRE vs OpenJDK vs Oracle JDK JRE(Java Runtime Environment),它是你运行一个基于Java语言应用程序的所正常需要的环境.如果你不是一个程序员的话 ...

  4. 采用Atlas+Keepalived实现MySQL读写分离、读负载均衡【转载】

      文章 原始出处 :http://sofar.blog.51cto.com/353572/1601552 ============================================== ...

  5. 1.2 从 ACID 到 CAP/BASE

    1.事务 事务(Tranction)是指,由一系列对系统中数据进行访问与更新操作,所组成的一个逻辑执行单元.狭义上的事务是指数据库事务. 事务有四个特性. 原子性:原子性要求事务只允讲有两种状态,全部 ...

  6. MySQL编译安装

    1.准备工作 其官方站点为http://www.mysql.com/ 为了避免发生端口冲突.程序冲突现象.建议先查询MySQL软件的安装情况,确认没有使用以RPM方式安装的mysql-server.m ...

  7. transition代替简单的animation注意事项

    一. transition 和 animation  不支持    Internet Explorer 9,以及更早的版本. 二. 要变化的属性 transition-property:要变化的属性, ...

  8. 《C和指针(Pointer on c)》 学习笔记(转自:http://dsqiu.iteye.com/blog/1687944)

    首先本文是对参考中三个连接的博客进行的整理,非常感谢三位博主的努力,每次都感叹网友的力量实在太强大了…… 第一章 快速上手 1.  在C语言中用/*和*/来注释掉这段代码,这个实际上并不是十分的安全, ...

  9. 30 GroupSock(Port)——live555源码阅读(四)网络

    30 GroupSock(Port)——live555源码阅读(四)网络 30 GroupSock(Port)——live555源码阅读(四)网络 简介 Port类的定义 Port的构造与全局的 &l ...

  10. Python自动化之socket初识

    1. os.popen() os.system(cmd)会直接输出命令的结果到屏幕上,返回一个状态码0或1. os.popen(cmd)会返回一个<open file 'dir', mode ' ...