我需要在主页的codeigniter网站上显示最近的两个wordpress帖子

时间:2013-06-24 07:31:17

标签: php wordpress codeigniter

请提供有关如何整合的代码。我将博客保存在public_html文件夹中,博客有一个数据库,网站还有我创建的其他数据库。

我在我的网站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 个答案:

答案 0 :(得分: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; ?>