yii和wp做博客
第一步,安装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做博客的更多相关文章
- 解决“用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示”的问题记录(备忘)
解决"用PicGo-2.3.0-beta5 + GitHub做博客图床,github仓库图片文件不显示"的问题记录(备忘) 历时几个小时百度,终于靠自己理解解决了GitHub仓库图 ...
- 牛腩学ASP.NET CORE做博客(视频)
牛腩学习ASP.NET CORE做的项目,边学边做. 目录: 01-dotnetcore网站部署到centos7系统上(时长 2:03:16) 02-前期准备及项目搭建 (时长:0:23:35) 03 ...
- 分享我做Dotnet9博客网站时积累的一些资料
从2019年使用WordPress搭建Dotnet9网站,到现在手撸代码开发,介绍中间使用的一些资源,绝无保留,希望对大家有用. 1. 申请域名.搭建WordPress网站 时间点:2019年11月 ...
- yii2实战教程之新手入门指南-简单博客管理系统
作者:白狼 出处:http://www.manks.top/document/easy_blog_manage_system.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文 ...
- 【五】将博客从jekyll迁移到了hexo
本系列有五篇:分别是 [一]Ubuntu14.04+Jekyll+Github Pages搭建静态博客:主要是安装方面 [二]jekyll 的使用 :主要是jekyll的配置 [三]Markdo ...
- 2021年Wordpress博客搭建
2021年WordPress博客搭建教程 这是一篇关于2021最新版的WP个人博客搭建教程.整篇文章会事无巨细的一步步讲述搭建博客的每一步. 0.前言 随着互联网和移动互联网的飞速发展,博客这一功能恍 ...
- 基于hexo+github搭建一个独立博客
一直听说用hexo搭建一个拥有自己域名的博客是很酷炫的事情~,在这十一花上半个小时整个hexo博客岂不美哉. 使用Hexo吸引我的是,其简单优雅, 而且风格多变, 适合程序员搭建个人博客,而且支持多平 ...
- 前博客 http://bbs.landingbj.com/mytopic.jsp?action=mytopic&username=57071
在工作学习的过程中,遇到了亮眼的技术点,或者 学习的心得体会,总想要记录下来,或是方便自己,或是帮助如同自己现在这般的新人.前人种树,后人乘凉.享受了前人留下的阴凉,也会考虑自己给后来者种下几棵树苗. ...
- 个人博客实现Archives查询小记
这两天正在做博客,刚刚遇到一个问题,就是需要在主页实现文档分类功能,即通过日期将文章进行按日期进行分类. 比如这样的: 我个人的想法是,查询所有文章的日期,然后将日期进行格式化,只留下年份和月份,然后 ...
随机推荐
- Windows Phone自带的语音识别
WindowsPhone下语音操作包括: 1.程序内部的语音识别,用户可以通过语音识别进行输入或完成相关任务 2.控制程序的语音命令,控制程序启动.打开,并可对页面跳转等进行操作 这篇文章将构建一个简 ...
- 微信封号浪潮再起 A货假代购还能在朋友圈泛滥多久?
你的微信朋友圈是不是很活跃?是不是被很多所谓的名品所包围?没错,这些很多都是A货或假代购的伎俩.如果xmyanke的微信朋友圈出现这些东东,我就会直接屏蔽他的朋友圈权限.具体方法是:打开他的微信详细资 ...
- cf#306D. Regular Bridge(图论,构图)
D. Regular Bridge time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 【定时任务|开机启动】Windows Server 2008/2012 计划任务配置(任务计划程序)每分钟执行BAT
打开计划任务快捷方式(在 “管理工具”内): C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\Tas ...
- loadrunner-27796错误寻求解决办法
Action.c(58): Error -27796: Failed to connect to server "www.baidu.com:80": [10048] Addres ...
- gcc 和g++区别
gcc和g++都是GNU的一个编译器;这两者的区别:1.从源文件上看,对于文件后缀(扩展名)为.c的test.c文件,gcc会把它看成是C程序,而g++则会把它看成是C++程序;而对于文件后缀(扩展名 ...
- Android学习笔记(十七)——数据库操作(下)
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 这一次我们来试一试升级数据库,并进行数据库的CRUD操作,其中, C 代表添加(Create) ,R 代表查询 ...
- huffman编码压缩算法(转)
参考:http://blog.csdn.net/sunmenggmail/article/details/7598012 笔试时遇到的一道题.
- 解析JSON插入数据库
<?php header("Content-Type:text/html;charset=utf-8"); include_once('./mysql.php'); $fil ...
- mysql 同步
http://dev.mysql.com/doc/refman/5.5/en/replication-howto.html http://blog.csdn.net/mycwq/article/det ...