-1

私はwordpress CMSを使用していて、サブドメインから5つの最近の投稿を表示してメインサイトに表示したいのですが、私が見つけた解決策は

 <?php
    global $switched;
    switch_to_blog(7);
    echo 'You switched from blog ' . $switched . ' to 7';
    restore_current_blog();
    echo 'You switched back.';
?>

また

<?php 
switch_to_blog( 2 ); // Switch to the blog that you want to pull posts from. You can see the ID when you edit a site through the Network Admin - the URL will look something like "http://example.com/wp-admin/network/site-info.php?id=2" - you need the value of "id", in this case "2" ?>

<h2>Recent Posts</h2>
<ul>

<?php
    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent ) {
        echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a> </li> ';
    }
?>
</ul>

<?php restore_current_blog(); // Restore the current blog ?>

しかし、IDはサブドメインの番号を見つける場所がわかりません..どこで見つけるか..助けてください

4

1 に答える 1