如何在 WordPress 多站点设置中显示来自其他站点的帖子?

发布于 2024-09-26 05:33:27 字数 216 浏览 0 评论 0原文

我使用 WordPress 3.0 的多站点功能设置了一个小型站点网络。我想创建另一个网站,从其他各个网站中提取某些帖子进行显示。这个新的“中心”站点对于用户来说似乎是它自己的独立站点(具有域映射),但其内容来自其他站点的帖子。

如何在 WordPress 多站点设置中从另一个站点获取帖子?可以根据网站名称查询帖子吗?最终结果需要是来自不同站点的按日期排序的帖子集合。

感谢您的帮助。

I have a small network of sites setup with WordPress 3.0's multisite feature. I would like to create another site which pulls certain posts from the various other sites to display. This new 'hub' site would seem like its own separate site to the user (with domain mapping), but its content is coming from the posts from the other sites.

How can I get posts from another site in a WordPress multisite setup? Can I query for posts based on the name of the site? The end result needs to be a collection of posts from the different sites sorted by date.

Thanks for your help.

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

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

发布评论

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

评论(2

哭了丶谁疼 2024-10-03 05:33:27

我遇到了类似的问题,我想从一个博客获取帖子并将其显示在另一个博客上,我想出了以下解决方案,您可以根据需要稍微修改该解决方案以满足您的需求

<?php
global $switched;
switch_to_blog(2); //switched to 2

// Get latest Post
$latest_posts = get_posts('category=-3&numberposts=6&orderby=post_name&order=DSC');
$cnt =0;?> 
<ul>
    <?php foreach($latest_posts as $post) : setup_postdata($post);?>
    <li>
        <a href="<?php echo get_page_link($post->ID); ?>" title="<?php echo $post->post_title; ?>"><?php echo  short_title('...', 7); ?></a>
    </li>                                
    <?php endforeach ; ?>

<?php restore_current_blog(); //switched back to main site ?>

我还限制了正在使用的字数如果您不想使用此功能,请简单使用

$post->post_title; 

希望它有所帮助。

I had the similar issue where I wanted to get posts from one blog and display it on an other I came up with the following solution which you could modify slightly to meet your needs if needed

<?php
global $switched;
switch_to_blog(2); //switched to 2

// Get latest Post
$latest_posts = get_posts('category=-3&numberposts=6&orderby=post_name&order=DSC');
$cnt =0;?> 
<ul>
    <?php foreach($latest_posts as $post) : setup_postdata($post);?>
    <li>
        <a href="<?php echo get_page_link($post->ID); ?>" title="<?php echo $post->post_title; ?>"><?php echo  short_title('...', 7); ?></a>
    </li>                                
    <?php endforeach ; ?>

<?php restore_current_blog(); //switched back to main site ?>

I'm also limiting the amount of words which is being out putted if you do not want this feature simple use

$post->post_title; 

Hope it helps.

醉酒的小男人 2024-10-03 05:33:27

通过直接数据库调用来设置这并不是非常困难。您可以使用 $wpdb 对象查询安装中任何站点的帖子。有关使用自定义数据库查询的信息,请参阅使用自定义选择查询显示帖子,但请记住,从 $wpdb->posts 中进行选择,您将需要访问您想要从中发布帖子的特定站点表。在默认的 WordPress 3 安装中,这将是 wp_12_posts,其中 12 是站点 ID。该 ID 可以在 wp_blogs 表中找到,或者通过查看管理菜单的“站点”部分中的 ID 列来找到。

This wouldn't be terribly difficult to set up with direct database calls. You can query posts from any site on the install with the $wpdb object. See Displaying Posts Using a Custom Select Query for information on using a custom database query, but keep in mind that instead of selecting from $wpdb->posts you're going to need to access the specific site table you want posts from. On a default Wordpress 3 install, this would be wp_12_posts where 12 is the site id. The id can be found in the wp_blogs table, or by looking at the ID column in the Sites section of the admin menu.

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