如何在WordPress多站点设置中显示来自其他站点的帖子? [英] How can I display posts from the other sites in a WordPress multisite setup?

查看:73
本文介绍了如何在WordPress多站点设置中显示来自其他站点的帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

感谢您的帮助.

推荐答案

我遇到了类似的问题,我想从一个博客获取帖子并在另一个博客上展示,我想出了以下解决方案,您可以对其稍加修改.满足您的需求

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; 

希望有帮助.

这篇关于如何在WordPress多站点设置中显示来自其他站点的帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆