如何在主WordPress站点上显示的子站点的多个文章如何

发布于 2025-01-27 06:05:51 字数 100 浏览 3 评论 0原文

我在主站点上有8-9个子站点。我想在主站点主页上的每个亚种博客中至少有2-3篇最新文章/帖子。是否有任何插件/小部件可以在主站点主题中输入或有任何代码,以发布每个subsite的多个帖子

I have 8-9 subsites on the main site. I would like to have at least 2-3 latest articles/posts from each of the subsite blogs on the main site home page. is there any plugin/widget that can do or is there any code that we can put in the main site theme to publish multiple posts from every single subsite

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聽兲甴掵 2025-02-03 06:05:51

您可以使用 switch_to_blog 函数函数以询问网络上任何网站的帖子。然后,您可能想做类似的事情:

// Switch to a particular site on the network
switch_to_blog( $site_id );

// Retreive the latest 3 posts
$args = array(
    'post_type'        => 'post',
    'posts_per_page'   => 3,
    'orderby'          => 'date',
     'order'           => 'DESC'
);
$latest_articles = new WP_Query( $args );

while ( $latest_articles->have_posts() ) {
    $latest_articles->the_post();
    // do some stuff such as the_title(), the_content(), etc.
}

// Restore the original query
wp_reset_query();

// Get back to the original site
restore_current_blog();

希望对您有所帮助!

You can use the switch_to_blog function in order to query posts from any site on the network. Then, you might want to do something like:

// Switch to a particular site on the network
switch_to_blog( $site_id );

// Retreive the latest 3 posts
$args = array(
    'post_type'        => 'post',
    'posts_per_page'   => 3,
    'orderby'          => 'date',
     'order'           => 'DESC'
);
$latest_articles = new WP_Query( $args );

while ( $latest_articles->have_posts() ) {
    $latest_articles->the_post();
    // do some stuff such as the_title(), the_content(), etc.
}

// Restore the original query
wp_reset_query();

// Get back to the original site
restore_current_blog();

Hope that helps!

一百个冬季 2025-02-03 06:05:51

谢谢@RedFox,但是我使用了扩展的插件网络。通过使用短代码,这使它变得更容易,并有助于增加每个子站点的帖子以在主站点上显示。

谢谢

thank you @redfox however i used plugin network extended. that made it easier by using the shortcode and it helped to increase posts from every sub site to display on main site.

thank you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文