我最终实现了我的想法。
我已经在中描述了在站点信息屏幕上创建自定义输入字段的过程this Post. 下面是完整的代码:
<?php
// Create custom Input Field on the WP-Admin > Network > Site Info Screen
// for the possibility to order sites manually
add_action(\'admin_footer\', \'pg_custom_site_options\');
function pg_custom_site_options(){
global $pagenow;
if( \'site-info.php\' == $pagenow ) {
global $details;
$blog_id = isset( $_REQUEST[\'id\'] ) ? intval( $_REQUEST[\'id\'] ) : 0;
if ( ! $blog_id ) wp_die( __(\'Invalid site ID.\') );
$saved_value = get_blog_option( $blog_id, \'blog_order\');
?>
<table style="display: none;">
<tr id="user16975_custom_options">
<th scope="row">Order</th>
<td><input type="text" size="5" name="blog[blog_order]" value="<?php echo esc_attr( $saved_value ) ?>" ></td>
</tr>
</table>
<script>
jQuery(function($){
$(\'.form-table tbody\').append($(\'#user16975_custom_options\'));
});
</script>
<?php
}
}
add_action(\'admin_init\', \'pg_save_custom_site_options\');
function pg_save_custom_site_options(){
global $pagenow;
if( \'site-info.php\' == $pagenow &&
isset($_REQUEST[\'action\']) &&
\'update-site\' == $_REQUEST[\'action\']
) {
// Use a default value here if the field was not submitted.
$new_field_value = \'0\';
if ( isset( $_POST[\'blog\'][\'blog_order\'] ) ) {
$new_field_value = intval( $_POST[\'blog\'][\'blog_order\'] );
// save option into the database
if( is_int($new_field_value) ){
update_blog_option( $_POST[\'id\'], \'blog_order\', $new_field_value );
}
}
}
}
?>
在每个站点获得其订单号后,我将其放置在wp\\u get\\u sites-array中
$all_standorte = wp_get_sites( $args );
// Get the order nr of each site and save it in the array
$pos = 0;
foreach( $all_standorte as $standort){
$standort_id = $standort[\'blog_id\'];
$blog_order = get_blog_option( $standort_id, \'blog_order\', \'0\');
$all_standorte[$pos][\'blog_order\'] = $blog_order;
$pos++;
}
最后一步是使用
usort().
// Sort Sites by Custom Order
function sort_sites_by_order($a, $b){
// ascending (aufsteigend)
return $a[\'blog_order\'] - $b[\'blog_order\'];
// descending (absteigend, der juengste Artikel zuerst)
// return $b[\'blog_order\'] - $a[\'blog_order\'];
}
usort($all_standorte, \'sort_sites_by_order\');