How can I display posts from the other sites in a WordPress multisite setup?

后端 未结 2 1982
感情败类
感情败类 2021-02-02 17:54

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 disp

相关标签:
2条回答
  • 2021-02-02 18:26

    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.

    0 讨论(0)
  • 2021-02-02 18:46

    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.

    0 讨论(0)
提交回复
热议问题