我建议使用get_sites()
而不是手工制作$wpdb
电话。
将此代码添加到主题functions.php
文件
function wpse365255_print_sites() {
$args = array(
\'number\' => 10000, // if you\'ve got more than 10,000 sites,
//you can increase this
\'public\' => 1,
\'spam\' => 0,
\'deleted\' => 0,
\'archived\' => 0,
\'site__not_in\' => array( 1, 2 ),
// this will exclude sites with ID 1 and 2
);
$sites = get_sites( $args ); // will return an array of WP_Site objects
$list = \'\';
foreach ( $sites as $site ) {
$details = get_blog_details( $site->blog_id );
if ( ! empty( $details ) ) {
$list .= \'<li>\';
$list .= \'<a href="\' . $details->siteurl . \'">\';
$list .= $details->blogname;
$list .= \'</a>\';
$list .= \'</li>\';
}
}
if ( ! empty( $list ) ) {
echo \'<ul>\' . $list . \'</ul>\';
}
}
然后,在你的
footer.php
文件中,将最初发布的代码替换为:
<?php
wpse365255_print_sites();
?>
通常最好不要在模板文件中定义函数,而是将它们放在
functions.php
并从模板文件中调用它们,这就是所要做的。(最好还是把它们挂到动作或过滤器挂钩上,但那是
a lesson for another day.)
WP_Site
class