2013-06-24 38 views
1

请提供如何集成的代码。我在public_html文件夹中保留了博客,博客有一个数据库,并且网站有我创建的其他数据库。我需要在主页的codeigniter站点显示最近的两个wordpress帖子。

我尝试了这些代码在我的网站index.php

<?php require('blog/wp-blog-header.php');?> 

<?php 
    $args = array('numberposts' => 2, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date"); 
    $postslist = get_posts($args); 

    foreach ($postslist as $post) : setup_postdata($post); ?> 
     <div class="events"> 
      <p><strong><?php the_date(); ?></strong></p> 
      <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p> 
     </div> 
<?php endforeach; ?> 

但显示像

Fatal error: Call to undefined function wp_get_recent_posts() in 
/home/sharelok/public_html/application/views/index.php on line 124 
+1

您需要包括'WP-负荷.php'文件,如果您在wp之外执行任何wp操作。 – Rikesh

回答

1

错误你可以试试这个

define('WP_USE_THEMES', false); 
require('blog/wp-load.php'); 
$postslist = get_posts(array('posts_per_page' => 2, 'orderby'=> 'post_date')); 
foreach($postslist as $post) : setup_postdata($post); ?> 
    <div class="events"> 
     <p><strong><?php the_date(); ?></strong></p> 
     <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p> 
    </div> 
<?php endforeach; ?> 
+0

致命错误:无法在/home/sharelok/public_html/blog/wp-includes/link-template.php上重新声明site_url()(以前在/home/sharelok/public_html/system/helpers/url_helper.php:42中声明)行1946 – leela

+0

我收到以上错误,但在本地它显示像(错误连接数据库) – leela

+2

@leela,这是因为,'Ci'和'WP'都有函数'site_url'和'require(' blog/wp-load.php');''WP'正在被包含在内,因此'site_usl'正在它的核心中被声明。所以,如果你可以重命名'CI'is'site_url',那么问题就会解决,但我建议你关注[这篇文章](http://philpalmieri.com/2009/06/codeigniter-and-wordpress-play -well-together /)和[this one](http://oscardias.com/development/php/codeigniter/integrating-wordpress-with-codeigniter/)。 –

相关问题