views:

485

answers:

2

Hi friends,

I use codeigniter and need to display last 3 posts at footer from blog as blabla.com/blog located.

when I create a test.php file as below. it works well,


test.php

<?php
// Include Wordpress 
define('WP_USE_THEMES', false);
require('./blog/wp-blog-header.php');
query_posts('showposts=3');
?>
<ul>
<?php while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>

but when I copy same code to footer_view.php of codeigniter structre, it doesnt work and giving error as below:

error at codeigniter footer_view:

Fatal error: Call to undefined method stdClass::set_prefix() in /blabla/blog/wp-settings.php on line 268

any idea what can be the problem? :/ appreciate helps!!

A: 

Have you thought about using the RSS feed from wordpress to display the blog posts with codeigniter? It would be a more flexible solution.

JoshHighland
i've been researching at google since i'd seen your advice, but I couldn't find anything :/ do you know any tut about that?
artmania
here is a good example of how to parse rss feeds with codeigniter http://www.nextbigleap.com/index.php/blog/post/simplepie-rss-class-and-codeigniter
JoshHighland
+1  A: 

I've used 3 tricks for getting WordPress content into CodeIgniter:

  1. Pull via XMLHttpRequest from a custom WP template (skip headers/footers/sidebars). I like this method as it is highly decoupled, and it makes for fast page loads.
  2. Pull via CURL or get_file*. This is similar to using XMLHttpRequests, but server side.
  3. Wrap WP in a library. This is more work, but the essence is calling the core WP object from a CI library. I prototyped this method last year, but found that #1 performed better (and it allowed me to move the content to another server later).

Note, you could also IFrame the page, but IFrames seem a bit hackish given #1 and #2.

Bruce Alderson
hi Bruce, thanks for great answer! I'm researching for your advices but can't find any particular info for my case, I want to go for #1 as you have recommended too. do you know any tut. or info link? appreciate!
artmania
I haven't seen a tutorial directly for #1, but any AJAX example would work: you're just pulling content from a URL.
Bruce Alderson