所有解释都是关于CDTuts
我创建了一个WordPress Network 我想从所有选定的子域博客中获取最近的帖子。我需要最新的All 按日期组织,不按博客ID组织。
我不想使用switch_to_blog 因此,使用foreach,因为我只在我切换的下一个博客中循环帖子。我想把这些帖子合并起来,按日期组织起来。我想您必须通过查询mysql而不是使用WP\\U查询来实现这一点。但我希望有一种更地道的方式来做这件事。这是要在首页底部制作的帖子列表,您可以看到,时间戳不是按数字的大小升序或降序。
我甚至试过这样做,但这也行不通。按Unix时间戳对帖子进行排序,以仅了解帖子仍按switch_to_blog 而不是及时。
<?php
switch_to_blog(1);
$main_posts = get_posts();
switch_to_blog(2);
$php_posts = get_posts();
switch_to_blog(3);
$wp_posts = get_posts();
switch_to_blog(4);
$mac_posts = get_posts();
switch_to_blog(4);
$psd_posts = get_posts();
switch_to_blog(1);
$posts = array_merge($main_posts, $php_posts, $wp_posts, $mac_posts, $psd_posts);
usort($post, get_post_time);
foreach($posts as $post){
?>
<li class="thumb"><a href="<?php echo the_permalink(); ?>">
<div class="site-name">
</div>
<div class="title">
<?php echo the_title(); ?><br> <?php echo get_post_time(); ?>
</div>
</a></li>
<?php }
?>
我还创建了一个函数,可以使用switch_to_blog. 这只适用于首页顶部的平铺。但我也在尝试对底部的最新帖子进行同样的处理。我无法创建偏移量,以便在保留6篇最新帖子的同时保留互动程序设计。这是基于之前的回答StackExchange
function global_latest_post($LatestBlogNumber,$LatestPostNumber, $LatestThumbSize, $LatestThumbNumber) {
$original_blog_id = get_current_blog_id();
$bids = array($LatestBlogNumber);
foreach($bids as $bid) {
switch_to_blog($bid);
$tiles = new WP_Query(\'posts_per_page=1\');
while ($tiles->have_posts()) : $tiles->the_post(); ?>
<a href="<?php echo the_permalink(); ?>" class="<?php echo $LatestThumbSize; ?> thumb-<?php echo $LatestThumbNumber; ?>">
<p class="cover">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p class="bold bottom">Read More →</p>
<h1><?php echo $LatestPostNumber; ?>. <?php echo the_title(); ?> in <?php bloginfo(\'name\'); ?></h1>
</a>
<?php
endwhile;
}
switch_to_blog( $original_blog_id ); //switched back to current blog
}