The easiest way to do it would be to use your blogs feed and include it with an RSS parser. Haven't got tech details to hand but a quick google will sort ya!
Hi guys,
Ok - i am integrating wordpress with one of my sites and ahve come across a curious issue
Basically I want to show the 3 latest blog posts on my sites homepage (which is outside of the WP installation - wordpress is sat in a directory called blog)
Now - i have tried various methods such as:
including the WP config within my sites homepage and looping through items:
require_once('blog/wp-config.php');
$news = $wpdb-get_results(SELECT ID,post_title FROM $wpdb-posts
WHERE `post_type`=\post\ AND `post_status`= \publish\ ORDER BY `post_date` DESC LIMIT $how_many);
foreach($news as $np){
printf (lia href=\index.php?p=%s\%s/a/li, $np-ID,$np-post_title);
}
Also tried including the wp-load file and doing it that way:
define('WP_USE_THEMES', false);
require('blog/wp-load.php');
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read more...</a></p>
<?php endwhile; ?>
The curiopus thing is whenever I include or require ANY kind of WP file (wp-config, wp-load.php, wp-blog-header.php) I just get a blank white homepage - no errors no nothing??
Any ideas or has anyone done something similar??
I COULD just use simplepie to pull in a feed or simply access the WP database directly but this way seems a lot cleaner as it uses the WP classes and objects to access and handle the data
I am using WP version 2.9.2
Any ideas??
The easiest way to do it would be to use your blogs feed and include it with an RSS parser. Haven't got tech details to hand but a quick google will sort ya!
Jack of all trades master of some
This will do exactly what you want:
Using your code and modifiying it so that it works
Code:<? require_once('wp-config.php'); global $wpdb; $news = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE post_type='post' AND post_status= 'publish' ORDER BY post_date DESC LIMIT 3"); foreach($news as $np){ printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title); } ?>
I have no idea what happened to the answer I posted here a few days ago, it must have been deleted, anyway, here's the answer:
<?
require_once('wp-config.php');
global $wpdb;
$news = $wpdb->get_results("SELECT ID,post_title FROM $wpdb->posts WHERE post_type='post' AND post_status= 'publish'
ORDER BY post_date DESC LIMIT 3");
foreach($news as $np){
printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
}
?>
So, the solution I gave doesn't work? Because, it works for me on 3 separate sites.
I don't think it's a bug, you could try including wp-load.php instead of wp-config.php which will bypass all the template and header stuff that wp-config loads.
Change the line to require_once('wp-load.php');
Is the page you want to show them on in a different directory to wp-config? if so you would probably need to go (if wp-config is one directory above):
require_once('../wp-config.php');
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks