我必须从WordPress的多站点网络上获取最后一篇文章。目前,我使用此代码在每个blog_id
:
<?php
$blogs = get_last_updated(\' \', 0, 1);
foreach ($blogs AS $blog);
switch_to_blog($blog["blog_id"]);
$lastposts = get_posts(\'numberposts=1&orderby=date\');
foreach($lastposts as $post) : setup_postdata($post);?>
但是如果我想得到最后一篇文章,而不是最后一篇文章的更新,我该怎么做呢?因为如果我更改并刷新一篇帖子,我会得到与主页上最后一篇一样的帖子。但这并不是真正的最后一篇帖子。Update - 这是完整版本,我还使用了restore\\u current\\u blog():
<?php
$blogs = get_last_updated(\' \', 0, 1);
foreach ($blogs AS $blog);
switch_to_blog($blog["blog_id"]);
$lastposts = get_posts(\'numberposts=1&orderby=date\');
foreach($lastposts as $post) : setup_postdata($post);?>
<div class="container-img">
<a class="anteprima_princ" href="<?php echo get_page_link($post->ID); ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_post_thumbnail(\'immagine-principale\'); ?></a>
</div>
<h2 class="entrytitlepost"><a href="<?php echo get_page_link($post->ID); ?>" title="<?php echo $post->post_title; ?>"><?php the_title(); ?></a></h2>
<div class="post-content-princ">
<p><?php the_content_rss(\'...\', FALSE, \'\', 40); ?></p>
<div id="lt">
<div id="leggitutto"><div id="croce"><div id="alto"></div><div id="largo"></div></div><a class="lt" href="<?php echo get_page_link($post->ID); ?>" title="<?php echo $post->post_title; ?>">LEGGI TUTTO</a></div>
</div>
</div>
<?php endforeach ; ?>
<?php restore_current_blog(); //switched back to main site ?>