Создание произвольного статуса записи WordPress
Добавление этого фрагмента в functions.php вашей темы WordPress позволит вам добавить пользовательские сообщения о состоянии для каждой записи или страницы.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
add_filter( 'display_post_states','custom_post_state'); function custom_post_state( $states ) { global $post; $show_custom_state = get_post_meta( $post->ID, '_status' ); if ( $show_custom_state ) { $states[] = __( '<span class="custom_state '.strtolower($show_custom_state[0]).'">'.$show_custom_state[0].'</span>' ); } return $states; } add_action( 'post_submitbox_misc_actions', 'custom_status_metabox' ); function custom_status_metabox(){ global $post; $custom = get_post_custom($post->ID); $status = $custom["_status"][0]; $i = 0; /* ----------------------------------- */ /* Array of custom status messages */ /* ----------------------------------- */ $custom_status = array( 'Spelling', 'Review', 'Errors', 'Source', 'Rejected', 'Final', ); echo '<div class="misc-pub-section custom">'; echo '<label>Custom status: </label><select name="status">'; echo '<option class="default">Custom status</option>'; echo '<option>-----------------</option>'; for($i=0;$i<count($custom_status);$i++){ if($status == $custom_status[$i]){ echo '<option value="'.$custom_status[$i].'" selected="true">'.$custom_status[$i].'</option>'; }else{ echo '<option value="'.$custom_status[$i].'">'.$custom_status[$i].'</option>'; } } echo '</select>'; echo '<br /></div>'; } add_action('save_post', 'save_status'); function save_status(){ global $post; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ return $post->ID; } update_post_meta($post->ID, "_status", $_POST["status"]); } add_action( 'admin_head', 'status_css' ); function status_css() { echo '<style type="text/css"> .default{font-weight:bold;} .custom{border-top:solid 1px #e5e5e5;} .custom_state{ font-size:9px; color:#666; background:#e5e5e5; padding:3px 6px 3px 6px; -moz-border-radius:3px; } /* ----------------------------------- */ /* change color of messages bellow */ /* ----------------------------------- */ .spelling{background:#4BC8EB;color:#fff;} .review{background:#CB4BEB;color:#fff;} .errors{background:#FF0000;color:#fff;} .source{background:#D7E01F;color:#333;} .rejected{background:#000000;color:#fff;} .final{background:#DE9414;color:#333;} </style>'; } |
Возможна данный фрагмент будет полезен для разработки вашего плагина или темы с дополнительными настройками. Полезно для статуса товара или объявлений на сайте. Удачи в разработке.

/*

- Базовый курс по веб-дизайну;
- Верстка сайтов;
- Общий курс по CMS WordPress и продолжение курса по разработке шаблонов;
- Разработка сайтов на PHP.