2010-07-06 82 views
1

我有建立一個網站,是部分靜態HTML和部分WordPress的客戶端。 Wordpress僅適用於博客,而靜態頁面適用於網站內容的其餘部分,包括主頁。是否可以在Wordpress安裝之外整合Wordpress內容?

這位同樣的客戶希望能夠從博客中「拉」最近的博客文章和評論計數,並將它們發佈到主頁上。

我對Wordpress並不熟悉,所以我張貼這個問題來了解這是否可能。如果是這樣,我自然會想知道「怎麼樣?」但這是爲了讓球滾動。

歡迎提供任何建設性意見。謝謝!

回答

2

如果你在遠程服務器上,你可以使用WordPress內置的RSS或XMLRPC接口。

如果你是在同一臺服務器上,該代碼段對WP 2.7進行測試,但可能會在3.0以及工作

<?php 


    $number = 5; 
    $wordpress_header = "/path/to/wordpress/wp-blog-header.php"; 

      // Include wordpress header 
      if (file_exists($wordpress_header)) 
      { 
      include ($wordpress_header); 

      $myposts = get_posts('numberposts=$number&offset=0&category=0'); 

      echo "<ul class='Bloglinks'>"; 

      foreach(array_slice($myposts, 0, $number) as $post) 
      { 
       echo '<li><a href="'; 
       the_permalink(); 
       echo '">'; 
       the_date(); 
       echo " "; 
       the_title(); 
       echo '</a></li>'; 
      } 

      echo "</ul>"; 

      } 
      else 
      { 
      echo "Unable to connect to Wordpress header file."; 
      die(); 
      }  


?> 
1

確定你可以從wp數據庫中獲取你想要的任何東西。有一個表格中包含所有帖子的帖子。只需連接通過它就像你會任何其他數據庫和查詢!

+0

如果你要手動從數據庫中提取,只要確保你''只查看'post_status ='發佈''的帖子,Wordpress也會在那裏存儲草稿。如果您只對博客文章感興趣,請確保'post_type ='post'' – joeynelson 2010-07-06 14:03:46