2009-09-22 42 views

回答

2

最簡單的方法是使用您的Wordpress RSS供稿。

使用file_get_contents()cURL下載更多控件。

simpleXML解析並輸出。

您可能想將它緩存在某處......您可以使用APC user functionsPEAR::Cache_Lite

編輯:代碼會是這個樣子(你想要更多的錯誤檢查和東西 - 這僅僅是讓你開始):

$xmlText = file_get_contents('http://www.blabla.com/blog/feed/'); 

$xml = simplexml_load_string($xmlText); 

foreach ($xml->item as $item) 
{ 
    echo 'Blog Post: <a href="' . htmlentities((string)$item->link) . '">' 
     . htmlentities((string)$item->title) . '</a>'; 

    echo '<p>' . (string)$item->description . '</p>'; 
} 
+0

uuu它聽起來不是那麼容易其實:)很多步驟...我正在研究你的建議的細節,謝謝! – 2009-09-22 10:57:59

+0

@artmania:由於你的主站點和你的博客都在同一臺服務器上,並且都使用php,所以這種技術可能是不必要的,儘管在某些方面它比你所做的要靈活一點 – Brian 2009-09-22 11:50:22

-1

我想最簡單的解決方法是直接拿帖子從數據庫。

+2

圍繞另一個程序內部 - 你是一個從災難升級的wordpress ... – Greg 2009-09-22 11:25:22

1

嘿剛剛在網上找到了一個解決方案;

http://www.corvidworks.com/articles/wordpress-content-on-other-pages

的偉大工程!

<?php 
// Include Wordpress 
define('WP_USE_THEMES', false); 
require('blog/wp-blog-header.php'); 
query_posts('showposts=3'); 


?>  
<?php while (have_posts()): the_post(); ?> 
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
<?php endwhile; ?> 
2

使用WordPress的最佳實踐,你不應該裝WP-博客 - 的header.php,而是WP-load.php,因爲它用於此目的專門創建的。

在此之後,使用the WP_Query objectget_posts()。有關如何使用WP_Query的示例,請參見WordPress代碼上的The Loop頁面。儘管如果您使用WordPress以外的其中任何一種都不重要,那麼幹擾的可能性就會降低,例如GET參數。

例如,使用WP_Query:

<?php 
$my_query = new WP_Query('showposts=3'); 
while ($my_query->have_posts()): $my_query->the_post(); 
?> 
<h1><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h1> 
<?php endwhile; ?> 

或者,使用get_posts():

<?php 
global $post; 
$posts = get_posts('showposts=3'); 
foreach($posts as $post) : 
?> 
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> 
<?php endforeach; ?> 

希望這有助於! :)