簡體   English   中英

我需要在我的Codeigniter網站上顯示最近的兩個wordpress帖子

[英]I need to show recent two wordpress posts in my codeigniter site at home page

請提供有關如何集成的代碼。 我將博客放在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

你可以試試這個

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; ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM