add unique_field
This commit is contained in:
39
dzenews.php
39
dzenews.php
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function add_custom_unique_field() {
|
||||||
|
// Добавляем поле "Добавить в unique" к каждому посту
|
||||||
|
add_meta_box(
|
||||||
|
'add_to_unique_meta_box',
|
||||||
|
'Эксклюзив',
|
||||||
|
'add_to_unique_meta_box_callback',
|
||||||
|
'post',
|
||||||
|
'side',
|
||||||
|
'default'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_to_unique_meta_box_callback($post) {
|
||||||
|
// Получаем текущее значение поля "Добавить в unique"
|
||||||
|
$add_to_unique = get_post_meta($post->ID, 'add_to_unique', true);
|
||||||
|
|
||||||
|
// Выводим поле в метабоксе
|
||||||
|
?>
|
||||||
|
<label for="add_to_unique">
|
||||||
|
<input type="checkbox" name="add_to_unique" id="add_to_unique" <?php checked($add_to_unique, 'on'); ?> />
|
||||||
|
Эксклюзивный материал
|
||||||
|
</label>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function save_custom_unique_field($post_id) {
|
||||||
|
// Сохраняем значение поля "Добавить в unique"
|
||||||
|
if (isset($_POST['add_to_unique'])) {
|
||||||
|
update_post_meta($post_id, 'add_to_unique', 'on');
|
||||||
|
} else {
|
||||||
|
delete_post_meta($post_id, 'add_to_unique');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавляем метабокс и сохраняем значения при сохранении поста
|
||||||
|
add_action('add_meta_boxes', 'add_custom_unique_field');
|
||||||
|
add_action('save_post', 'save_custom_unique_field');
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
setlocale(LC_TIME, 'ru_RU.UTF-8');
|
setlocale(LC_TIME, 'ru_RU.UTF-8');
|
||||||
|
|
||||||
|
require get_template_directory().'/dzenews.php'; //add support dzen
|
||||||
|
|
||||||
function theme_setup()
|
function theme_setup()
|
||||||
{
|
{
|
||||||
add_theme_support('menus');
|
add_theme_support('menus');
|
||||||
|
|||||||
Reference in New Issue
Block a user