我想根据一些日期检查更改posts表中每一行的背景色。
我需要更改的css是tr#post nnnn{背景颜色:$myColor},其中nnnn是post编号,$myColor是由5种预定义颜色组成的数组。
我已经考虑过如何进行这项工作,并提出了以下提纲,但如果能就我是否朝着正确的方向前进以及解决这类问题的标准流程提供一些建议,我将不胜感激。
这是一般的伪想法。。。
add_action( \'admin_print_styles-edit.php\', \'my_order_highlighter\' ); // After some searching I decided this would be the place to attach my function...
function my_order_highlighter() {
$order_n = get Order number
$date_o = get order date
$date_r = get requested date
$date_t = get todays date
$order_status = get order status (shipped/processing)
h_color = 1:red, 2:pink, 3:orange, 4:light-orange, 5:green
For each order displayed on the page…
If ($order_status == \'shipped\') {
// style the background colour for the current order row as \'5\' - "Completed"
<style> tr.$order_n {background-color:#get_h_color(5)}</style>
}
// order is NOT shipped so check if there is a \'requested date\' entered…
if ($date_r is set) {
// If due date is less than or equal to 3days away…
If ($date_t - $date_r <= 3days) {
// style the background colour for the current order row as \'3\' - "Needs attention"
<style> tr.$order_n {background-color:get_h_color(3)}</style>
}
// Due date is more than 3days away so style row as \'4\' "Upcoming"
<style> tr.$order_n {background-color:#get_h_color(4)}</style>
}
// No requested date entered so check if it is 5 days or more since order…
If ($date_t - $date_o >= 5days) {
// style the background colour for the current order row as \'1\' - "Needs URGENT attention"
<style> tr.$order_n {background-color:#get_h_color(1)}</style>
}
//otherwise, style row as \'4\' "Upcoming"
<style> tr.$order_n {background-color:#get_h_color(4)}</style>
}
这是一个可行的想法,还是我找错了地方来实现这一点?