Loading Subdomain post in the main domain?

Asked

Viewed 413 times

-1

I have a Wordpress MU installation. Could someone tell me how I do to load blog posts on Subdomain on my main domain?

  • One option is you use RSS Feed Wordpress works with some plugins that might be interesting, take a look at wordpress.org/plugins/tags/rss-feed

  • Hi, welcome to [en.so]. MU has been called Multisite since version 3.0 of WP. Is your installation 2.9 or lower? I doubt that this is your case, but only confirming...

  • You can upload the file wp-load.php to display the posts. Check out these links that will help you: http://www.maxvianna.net/wordpress/showos-posts-de-um-blog-wordpress-em-uma-pagina-html/ http://www.lucaskreutz.com.br/blog/2011/06/18/como-displar-posts-de-blog-wordpress-na-home-de-um-site/

2 answers

0

It’s just a matter of using the function switch_to_blog() and switch to the desired blog, make a query consultation of blog posts and use the same function to switch back to the original blog.

Create a plugin Must Use (always active and available throughout the network) and put the following code:

if( !function_exists('get_blog_posts') )
{
    function get_blog_posts( $blog_id, $args = array() )
    {
        $current_blog_id = get_current_blog_id();
        switch_to_blog( $blog_id );

        $posts = get_posts( $args );
        switch_to_blog( $current_blog_id ); // get_posts já foi feito, podemos restaurar

        if( $posts )
            return $posts;

        return false;
    }
}

Then, in the template or in any function within functions.php, use the following, adjusting the $blog_id_consultar and the $parametros. Note that echo print_r() is just for checking, make a loop of $posts_do_blog to print the HTML:

<?php 
if( function_exists('get_blog_posts') ) { 
    $blog_id_consultar = '3';
    $parametros = array(); // VIDE http://codex.wordpress.org/Function_Reference/get_posts
    $posts_do_blog = get_blog_posts( $blog_id_consultar, $parametros );
    if( $posts_do_blog ) {
        echo '<pre>' . print_r( $posts_do_blog, true ) . '</pre>';
    }
}
?>

0

<?php
query_posts('showposts=4'); //Query WordPress para listar os últimos 4 posts
?>
<?php while (have_posts ()): the_post(); ?>
    <h2>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </h2>
    <p><?php the_author(); ?> | <?php the_date(); ?>
<?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
    <?php the_excerpt(); ?>
<?php endwhile; ?>

I’m using this code, I want it to load the posts of another Wordpress blog.

  • Please use the button Ask a question to create your own question. You asked a question in a reserved space for answers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.