Linking wordpress blog to CodeIgniter View

2019-06-15 00:11发布

问题:

Well, here's the deal. I have this site with a framework called codeigniter. It's a MVC framework in PHP. I'm trying to use the wordpress API in order to set up a view in CodeIgnite that uses the wordpress API to get blog posts.

so the blog is in /wp-blog/, and the codeigniter framework is set up in /system/. so in the codeigniter view, I call require_once('/wp-blog/wp-load.php'); the wp-load file opens a config file with the database info on it. However, when i call it from my view, it doesn't work. However, when it's called from /wp-blog/index.php, it has no problem showing me the database

I don't know if it's a permissions issue. I'm clearly able to access the config file, because I get an error message that says 'username'@'localhost' and the username is right.

so if they are both getting the same file, and both executing the same file with the mysql_connect() function, why would one only work from inside the blog, and one does not work?

Here's the error:

A PHP Error was encountered

Severity: Warning

Message: mysql_connect() [function.mysql-connect]: Access denied for user 'theuser'@'localhost' (using password: YES)

Filename: wp-includes/wp-db.php

回答1:

Your approach is wrong. Your CodeIgniter controller needs to run a curl request to the blog's XML-RPC API endpoint and process the response, then display it as you need to.

A second option is to just use an iFrame on the page, although iFrames were outlawed at some point in 2005.