問題描述

當你註冊一個這樣的自定義列:

//Register thumbnail column for au-gallery type
add_filter('manage_edit-au-gallery_columns', 'thumbnail_column');
function thumbnail_column($columns) {
$columns['thumbnail'] = 'Thumbnail';
return $columns;
}

默認情況下,它顯示為右側的最後一個。如何更改訂單?如果我想將上述列顯示為第一個或第二個列呢?

先謝謝你

最佳解決方案

你基本上是問一個 PHP 問題,但我會回答,因為它在 WordPress 的上下文中。您需要重新構建列數組,將列插入到您要保留的列之前:

add_filter('manage_posts_columns', 'thumbnail_column');
function thumbnail_column($columns) {
  $new = array();
  foreach($columns as $key => $title) {
    if ($key=='author') // Put the Thumbnail column before the Author column
      $new['thumbnail'] = 'Thumbnail';
    $new[$key] = $title;
  }
  return $new;
}

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。