嘿,我这里有个代码:
if ( !function_exists(\'AddThumbColumn\') && function_exists(\'add_theme_support\') ) {
// for post and page
add_theme_support(\'post-thumbnails\', array( \'post\', \'page\' ) );
function AddThumbColumn($cols) {
$cols[\'thumbnail\'] = __(\'Header Images\');
return $cols;
}
function AddThumbValue($column_name, $post_id) {
echo \'Header Image data here\';
}
add_filter( \'manage_pages_columns\', \'AddThumbColumn\' );
add_action( \'manage_pages_custom_column\', \'AddThumbValue\', 10, 2 );
function AddThumbColumn2($cols) {
$cols[\'cssColor\'] = __(\'CSS Color\');
return $cols;
}
function AddThumbValue2($column_name, $post_id) {
//code goes here for second column
}
add_filter( \'manage_pages_columns\', \'AddThumbColumn2\' );
add_action( \'manage_pages_custom_column\', \'AddThumbValue2\', 10, 2 );
}
这适用于创建两个单独的列(标题图像,CSS颜色),但它似乎以CSS颜色复制标题图像中的数据。。?
为了让每一列都有自己的数据,我遗漏了什么?
最合适的回答,由SO网友:Milo 整理而成
附加到的功能manage_pages_custom_column
如果要激发每个自定义列,则必须检查函数中列的名称,以仅输出该特定列的数据:
add_action( \'manage_pages_custom_column\', \'AddColumnValue\', 10, 2 );
function AddColumnValue( $column_name, $post_id ) {
if( \'thumbnail\' == $column_name ):
echo \'Header Image data here\';
elseif( \'cssColor\' == $column_name ):
//code goes here for second column
endif;
}