Using Wordpress Code on Home Page

Permalink
I'm using C5 for general content and wordpress for blogging on a site I'm doing. No crazy integration, just a subdirectory with wordpress and the main site with c5. I'll make a custom WP theme. But I'd like to display the recent blog posts on my site's homepage.

I'd like to use the code here:http://codex.wordpress.org/Integrating_WordPress_with_Your_Website...

This is basically just a code snippet saying "include the core wordpress stuff, and pull out the latest 3 blog posts". However, my code works fine in a regular old php file. But when I try to call the same include files in my theme files, or even on the site root's index.php file (which calls dispatcher.php), there's an "error connecting to the (wordpress) database".

I've not dug deep enough or learned enough to know how to require WP files in a C5 theme without causing errors. Any help y'all?

clmedia
 
goldfish replied on at Permalink Reply
goldfish
Unless there's info you really need from the WP Loop, I'd first try using the built in C5 RSS block to display your WP Blog's RSS feed - Definitely the easiest way to go.
clmedia replied on at Permalink Reply
clmedia
I may have to if that's the only way. What makes it so difficult just to connect to the WP db? Not asking for step by step, but in general, if I had to accomplish this what would it take?
goldfish replied on at Permalink Best Answer Reply
goldfish
It would take some hacking to get it to work as I'm guessing when you include the WP functions in the C5 pages, C5 is trying to find the WP functions in its core.

Another less than elegant but quick way to do this is use CURL to save the output of that plain 3-post PHP page you made to a static HTML file. Then include that HTML file in your C5 theme in the appropriate place. Then set up a CRON job to refresh the plain PHP every so often. RSS is more robust, but if you need the full content/format of your WP posts, that's an easy way to do it. I'd also strongly consider an iframe. See thread here:http://www.concrete5.org/community/forums/chat/wordpress-andamp-con...
jcrens8392 replied on at Permalink Reply
jcrens8392
This was a few months ago but figured I'd reply b/c I just finished doing this.

I don't like to load the wp core b/c it's way too much overhead if all you need to do is display a few posts on your homepage. Instead I just access mysql directly with this...obviously you'll have to style it how you want. I'm just displaying 3 blog posts in the footer of the homepage. You can see it in action athttp://www.rlmseo.com/ :

/** 
 * Get 6 most recent posts from WordPress 
 */
$dbUser = 'dbuser';
$dbPass = 'dbpass';
$dbHost = 'localhost';
$dbName = 'dbname';
$conn = mysql_connect($dbHost, $dbUser, $dbPass);
if(!$conn) {
    $aDebug['Unable to connect to DB'] = mysql_error();
}elseif(!mysql_select_db($dbName, $conn)) {
    $aDebug['Unable to select database'] = mysql_error();
}else{
    $sQuery = "SELECT post_date, post_content, post_title, post_excerpt, post_name FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 3";
    $rPosts = mysql_query($sQuery, $conn);
jcrens8392 replied on at Permalink Reply
jcrens8392
What's up with the code posting, am I doing that wrong?
olliephillips replied on at Permalink Reply
olliephillips
Your last code tag needs a forward slash. Nice job re the code, I have something similar I wrote a while back

http://blog.eantics.co.uk/using-wordpress-data-on-your-website/...