Have wordpress as a module or extension in Yii

2020-06-23 05:01发布

I would like to add a blog to a web site. Couldn't find any good blog extension for Yii, so I decided to just use Wordpress. (Please let me know if there's a better way)

I could just extract wordpress in the root folder and run it.

http://www.example.com/wordpress

However, the Yii framework has its index.php on root folder so I will have to make wordpress either a module or extension (I think) unless I put the Yii framework in a root/yiiFolder and use root/wordpress to separate the two. Also, the main layout will have to be different than the Yii default main layout. Otherwise, the blog will share the same header and footer structure of Yii.

Could someone give me an example on how Yii framework call a non-yiiframework site?

标签: wordpress yii
3条回答
萌系小妹纸
2楼-- · 2020-06-23 05:33

You can include wordpress as a library, and require_once 'wp_config.php' in index.php. Then you can call wordpress function directly.

查看更多
够拽才男人
3楼-- · 2020-06-23 05:38

If you are having the following error:

include(Translation_Entry.php): failed to open stream: No such file or directory

then you need to disable Autoload, for example like this:

spl_autoload_unregister(array('YiiBase','autoload'));
$wp=dirname(__FILE__).'/../../../../wp-load.php'; 
require_once($wp);
spl_autoload_register(array('YiiBase','autoload'));
查看更多
ゆ 、 Hurt°
4楼-- · 2020-06-23 05:42

http://wpengineer.com/1038/embed-wordpress-functions-outside-wordpress/ - here is described how to call wordpress functions from outside wordpress. I tried the same thing from Yii layout and now I'm facing strange error. include(Translation_Entry.php): failed to open stream: No such file or directory. I need to look a little more into this.

Other than that - this solution (if you manage to configure it) should give you what you want.

查看更多
登录 后发表回答