Видаляємо підменю Теми. Виводимо помилки на сторінці теми. Метабокс для аудіо файлів.
Додавання коду до файлу functions.php вашої теми, видалить для всіх користувачів пункт Themes, крім користувача із зазначеним у коді id. Ви можете дозволити змінювати теми тільки собі.
1 2 3 4 5 6 7 8 9 |
add_action( 'admin_init', 'slt_lock_theme' ); function slt_lock_theme() { global $submenu, $userdata; get_currentuserinfo(); if ( $userdata->ID != 1 ) { unset( $submenu['themes.php'][5] ); unset( $submenu['themes.php'][15] ); } } |
Виводимо повідомлення про помилку
Додавання тексту помилки та виведення її на сторінці вибору теми. Просто додаємо код у файл functions.php.
1 2 3 4 5 6 |
add_action( 'admin_notices', 'custom_error_notice' ); function custom_error_notice(){ global $current_screen; if ( $current_screen->parent_base == 'themes' ) echo '<div class="error"><p>Warning - If you modify template files this could cause problems with your website.</p></div>'; } |
Код перевірено, все працює.
Метабокс для додавання аудіо записів
Думаю, буде цікаво попрацювати з кодом для виведення аудіофайлу на сторінці за допомогою метабоксу. У метабоксі можна легко вибрати потрібний аудіо файл із медіа бібліотеки.
Всього у нас буде два коди. Перший код вставляємо у файл functions.php.
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 |
add_action("admin_init", "audio_init"); add_action('save_post', 'save_audio_link'); function audio_init(){ add_meta_box("mp3-audio", "MP3 AUDIO", "audio_link", "post", "normal", "low"); } function audio_link(){ global $post; $custom = get_post_custom($post->ID); $link = $custom["link"][0]; $count = 0; echo '<div class="link_header">'; $query_audio_args = array( 'post_type' => 'attachment', 'post_mime_type' =>'audio', 'post_status' => 'inherit', 'posts_per_page' => -1, ); $query_audio = new WP_Query( $query_audio_args ); $audio = array(); echo '<select name="link">'; echo '<option class="audio_select">SELECT AUDIO FILE</option>'; foreach ( $query_audio->posts as $file) { if($link == $audio[]= $file->guid){ echo '<option value="'.$audio[]= $file->guid.'" selected="true">'.$audio[]= $file->guid.'</option>'; }else{ echo '<option value="'.$audio[]= $file->guid.'">'.$audio[]= $file->guid.'</option>'; } $count++; } echo '</select><br /></div>'; echo '<p>Selecting an audio file from the above list to attach to this post.</p>'; echo '<div class="audio_count"><span>Files:</span> <b>'.$count.'</b></div>'; } function save_audio_link(){ global $post; if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ return $post->ID; } update_post_meta($post->ID, "link", $_POST["link"]); } add_action( 'admin_head', 'audio_css' ); function audio_css() { echo '<style type="text/css"> .audio_select{ font-weight:bold; background:#e5e5e5; } .audio_count{ font-size:9px; color:#0066ff; text-transform:uppercase; background:#f3f3f3; border-top:solid 1px #e5e5e5; padding:6px 6px 6px 12px; margin:0px -6px -8px -6px; -moz-border-radius:0px 0px 6px 6px; -webkit-border-radius:0px 0px 6px 6px; border-radius:0px 0px 6px 6px; } .audio_count span{color:#666;} </style>'; } function audio_file_url(){ global $wp_query; $custom = get_post_custom($wp_query->post->ID); echo $custom['link'][0]; } |
Другий код вставляємо на те місце вашої теми, де необхідно вивести адресу прикріпленого файлу.
1 2 3 |
<? audio_file_url() ?> |
Далі завантажуємо новий файл і вибираємо його у створеному метабоксі, після чого він буде відображено на сторінці в потрібному місці. Успіхів у розробці.
/*
- Базовий курс з веб-дизайну;
- Верстка сайтів;
- Загальний курс CMS WordPress та продовження курсу з розробки шаблонів;
- Розробка сайтів на PHP.