我使用了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不知道在哪里可以找到子域的数量..在哪里找到它...请帮忙
答案 0 :(得分:0)
即使您使用PHP来抓取子域所在的文件夹,Bluehost子域也不容易识别。
最好的办法是让列出子域的所有脚本都可以访问文本文件。阅读该文件并使用它。