在wordigniter视图中从Wordpress到WP的帖子 [英] getting posts from Wordpress to out of WP in codeigniter view
问题描述
我使用codeigniter,并需要显示最后3个帖子从博客的blabla.com/blog位于博客。
当我创建一个test.php文件如下。
test$ b $ b
<?php
//包含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>
但是当我将相同的代码复制到codeigniter structre的footer_view.php时,它不工作,
:
>致命错误:调用未定义的方法
stdClass :: set_prefix()in
/blabla/blog/wp-settings.php
在第268行上
< blockquote>
任何想法可能是什么问题? :/欣赏帮助!!
解决方案我使用3个技巧将WordPress内容输入CodeIgniter:
- 通过XMLHttpRequest从自定义WP模板(跳过页眉/页脚/边栏)拉。我喜欢这种方法,因为它是高度解耦,并且它可以快速加载页面。
- 通过CURL或
get_file *
这类似于使用XMLHttpRequests,但是类似于服务器端。
- 在库中包装WP。这是更多的工作,但实质是从CI库调用核心WP对象。我在去年对这种方法进行了原型设计,但发现#1表现更好(并且允许我稍后将内容移动到另一台服务器)。
请注意,您也可以IFrame页面,但iframe似乎有点麻烦给予#1和#2。
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!!
解决方案I've used 3 tricks for getting WordPress content into CodeIgniter:
- 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.
- Pull via CURL or
get_file*
. This is similar to using XMLHttpRequests, but server side.- 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.
这篇关于在wordigniter视图中从Wordpress到WP的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!