Добрый день народ, вывод произвольного типа записи из определенных таксономий
25.01.2015, 12:35. Показов 1237. Ответов 1
Подскажите пожалуйста есть тип записи фильм и 4 таксономии для него страны фильмов, год фильмов, жанр фильмов и статус фильма в статусе термы в прокате, в архиве, и ожидаемые.
хочу на главной через шаблон станицы выводить все фильмы кроме категорий в архиве и ожидаемые
| PHP | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| <?php
$args = array(
'post_type' => 'film',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'genre-film',
'field' => 'slug',
'terms' => array( 'комедия','боевик'),
),
array(
'taxonomy' => 'status-film',
'field' => 'slug',
'terms' => 'в-архиве','ожидаемые',
'operator' => 'NOT IN',
)
)
);
$posts = query_posts( $args );
?> |
|
на главной вроде все как надо работает.... но как сделать вывод на отдельном шаблоне taxonomy-year-film.php для вывода фильмов в прокате 2014 года третий день думаю нечего не могу придумать
код function.php
| PHP/HTML | 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| add_action('init', 'film_type_init');
function film_type_init() {
// описываем наш тип контента
$labels = array(
'name' => _x( 'Фильмы', 'post type general name' ),
'singular_name' => _x( 'Фильм', 'post type singular name' ),
'add_new' => _x( 'Добавить новый', 'film' ),
'add_new_item' => 'Добавить новый фильм',
'edit_item' => 'Изменить фильм',
'new_item' => 'Новый фильм',
'view_item' => 'Просмотреть',
'all_items' => __( 'Все фильмы' ),
'search_items' => 'Найти фильм'
,'not_found' => 'Фильмов не найдено'
,'not_found_in_trash' => 'В корзине фильмов не найдено'
,'parent_item_colon' => ''
,'menu_name' => 'Фильмы'
);
$args = array(
'labels' => $labels
,'description' => ''
,'public' => true
,'publicly_queryable' => true
,'exclude_from_search' => null
,'show_ui' => true
,'show_in_menu' => true
,'menu_position' => null
,'menu_icon' => null
,'capability_type' => 'post'
,'hierarchical' => false
,'supports' => array('title','thumbnail','excerpt','comments')
,'taxonomies' => array('')
,'has_archive' => true
,'rewrite' => array( 'slug' => 'film' )
,'query_var' => true
,'show_in_nav_menus' => null
,'_builtin' => false, // это не встроенный тип данных
'_edit_link' => 'post.php?post=%d'
);
// регистрируем новый тип
register_post_type( 'film' , $args );
}
// подключаем таксономию (используемые технологии можно будет назначать как теги)
add_action( 'init', 'creat_film_taxonomy', 0 );
function creat_film_taxonomy(){
register_taxonomy(
'genre-film',
'film',
array (
'hierarchical' => TRUE,
'label' => __('Жанры Фильмов'),
'singular_label' => __('Жанр Фильма'),
'query_var' => 'genre-film',
'rewrite' => array( 'slug' => 'genre' )
)
);
register_taxonomy(
'year-film',
'film',
array (
'hierarchical' => TRUE,
'label' => __('Года Фильмов'),
'singular_label' => __('Год Фильма'),
'query_var' => 'year-film',
'rewrite' => array( 'slug' => 'year' )
)
);
register_taxonomy(
'country-film',
'film',
array (
'hierarchical' => TRUE,
'label' => __('Страны Фильмов'),
'singular_label' => __('Страна Фильма'),
'query_var' => 'country-film',
'rewrite' => array( 'slug' => 'country' )
)
);
register_taxonomy(
'status-film',
'film',
array (
'hierarchical' => TRUE,
'label' => __('Статусы Фильмов'),
'singular_label' => __('Статус Фильма'),
'query_var' => 'status-film',
'rewrite' => array( 'slug' => 'status' )
)
);
register_taxonomy(
'info-film',
'film',
array (
'hierarchical' => TRUE,
'label' => __('Информация Фильмов'),
'singular_label' => __('Инфа Фильма'),
'query_var' => 'info-film',
'rewrite' => array( 'slug' => 'info' )
)
);
}
// подключаем функцию активации мета блока (my_extra_fields)
add_action('add_meta_boxes', 'film_fields', 1);
function film_fields() {
add_meta_box( 'film_fields_meta', 'Информация о фильме:', 'film_fields_box_func', 'film', 'normal', 'high' );
}
// код блока
function film_fields_box_func( $post ){
?>
<input type="hidden" name="film_fields_nonce" value="<?php echo wp_create_nonce(__FILE__); ?>" />
<strong>Слоган:</strong><br/><br/><input name="film[слоган]" size="60" value="<?php echo get_post_meta($post->ID, 'слоган', 1); ?>" /><br/><br/>
<strong>Режисер:</strong><br/><br/><input name="film[режисер]" size="60" value="<?php echo get_post_meta($post->ID, 'режисер', 1); ?>" /><br/><br/>
<strong>В главных ролях:</strong><br/><br/><input name="film[в главных ролях]" size="60" value="<?php echo get_post_meta($post->ID, 'в главных ролях', 1); ?>" /><br/><br/>
<strong>Ограничения по возрасту:</strong><br/><br/><input name="film[возраст]" size="60" value="<?php echo get_post_meta($post->ID, 'возраст', 1); ?>" /><br/><br/>
<strong>Цена билета:</strong><br/><br/><input name="film[билет]" size="60" value="<?php echo get_post_meta($post->ID, 'билет', 1); ?>" /><br/><br/>
<strong>Время:</strong><br/><br/><input name="film[время]" size="60" value="<?php echo get_post_meta($post->ID, 'время', 1); ?>" /><br/><br/>
<strong>О фильме:</strong><br/><br/><textarea type="text" name="film[о фильме]" style="width:100%;height:120px;"><?php echo get_post_meta($post->ID, 'о фильме', 1); ?></textarea><br/><br/>
<strong>Ссылка на трейлер: http://www.youtube.com/watch?v=<span style="color: red" >aog_IX09as4</span></strong><br/><br/><input name="film[трейлер]" size="60" value="<?php echo get_post_meta($post->ID, 'трейлер', 1); ?>" /><br/><br/>
<?php
}
// включаем обновление полей при сохранении
add_action('save_post', 'film_fields_meta_update', 0);
/* Сохраняем данные, при сохранении поста */
function film_fields_meta_update( $post_id ){
if ( !wp_verify_nonce($_POST['film_fields_nonce'], __FILE__) ) return false;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return false;
if ( !current_user_can('edit_post', $post_id) ) return false;
if( !isset($_POST['film']) ) return false;
// Все ОК! Теперь, нужно сохранить/удалить данные
$_POST['film'] = array_map('trim', $_POST['film']);
foreach( $_POST['film'] as $key=>$value ){
if( empty($value) ){
delete_post_meta($post_id, $key);
continue;
}
update_post_meta($post_id, $key, $value);
}
return $post_id;
} |
|
Шаблон вывода template-film.php
| PHP/HTML | 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
| <?php
$args = array(
'post_type' => 'film',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'genre-film',
'field' => 'slug',
'terms' => array( 'комедия','боевик'),
),
array(
'taxonomy' => 'status-film',
'field' => 'slug',
'terms' => 'в-архиве','ожидаемые',
'operator' => 'NOT IN',
)
)
);
$posts = query_posts( $args );
?>
<?php if ($posts) : ?>
<?php foreach ($posts as $post) : setup_postdata ($post); ?>
<div class="art-Post">
<div class="art-Post-body">
<div class="art-Post-inner art-article">
<h2 class="art-PostHeaderIcon-wrapper">
<span class="art-PostHeader"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Постоянная ссылка на %s', 'kubrick'), the_title_attribute('echo=0')); ?>">
<div class="bnd"><?php the_title(); ?></div>
</a></span>
</h2>
<?php $icons = array(); ?>
<?php if (!is_page()): ?><?php ob_start(); ?><?php the_time(__('F jS, Y', 'kubrick')) ?>
<?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (!is_page()): ?><?php ob_start(); ?><?php _e('Автор', 'kubrick'); ?><?php $str = 'PGEgaHJlZj0iaHR0cDovL2ZlaGFwa2lkby5jb20vIiB0aXRsZT0iJiMxMDg0OyYjMTA3MjsmIzEwNzU7JiMxMDcyOyYjMTA3OTsmIzEwODA7JiMxMDg1OyAmIzEwOTI7JiMxMDg2OyYjMTA5MDsmIzEwODY7JiMxMDkwOyYjMTA3NzsmIzEwOTM7JiMxMDg1OyYjMTA4MDsmIzEwODI7JiMxMDgwOyI+OjwvYT4='; echo base64_decode($str);?> <a href="#" title="<?php _e('Автор', 'kubrick'); ?>"><?php the_author() ?></a>
<?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (0 != count($icons)): ?>
<div class="art-PostHeaderIcons art-metadata-icons">
<?php echo implode(' | ', $icons); ?>
</div>
<?php endif; ?>
<div class="art-PostContent">
<div class="thumbnail">
<?php if (has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<a class="simplebox" href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" >';
the_post_thumbnail('medium');
echo '</a>';
}?>
</div>
<table class="info">
<tbody>
<tr>
<td class="tdfilm"><strong>год:</strong></td>
<td class="tdfilm1">
<?php
$taxo_text = "";
$year = get_the_term_list( $post->ID, 'year-film', '', ', ', '' );
if ( '' != $year ) {
$taxo_text .= $year;}
if ( '' != $taxo_text ) {
echo $taxo_text;
}
?></td>
</tr>
<tr>
<td><strong>страна:</strong></td>
<td><?php
$taxo_text = "";
$country = get_the_term_list( $post->ID, 'country-film', '', ', ', '' );
if ( '' != $country ) {
$taxo_text .= $country;}
if ( '' != $taxo_text ) {
echo $taxo_text;
}
?></td>
</tr>
<tr>
<td><strong>жанр:</strong></td>
<td><?php
$taxo_text = "";
$genre = get_the_term_list( $post->ID, 'genre-film', '', ', ', '' );
if ( '' != $genre ) {
$taxo_text .= $genre;}
if ( '' != $taxo_text ) {
echo $taxo_text;
}
?></td>
</tr>
<tr>
<td><strong>слоган:</strong></td>
<td><?php echo get_post_meta($post->ID, 'слоган', 1); ?></td>
</tr>
<tr>
<td><strong>режисер:</strong></td>
<td><?php echo get_post_meta($post->ID, 'режисер', 1); ?></td>
</tr>
<tr>
<td><strong>в главных ролях:</strong></td>
<td><?php echo get_post_meta($post->ID, 'в главных ролях', 1); ?></td>
</tr>
<tr>
<td><strong>возраст:</strong></td>
<td><?php echo get_post_meta($post->ID, 'возраст', 1); ?></td>
</tr>
<tr>
<td><strong>Цена билета:</strong></td>
<td><?php echo get_post_meta($post->ID, 'билет', 1); ?></td>
</tr>
<tr>
<td><strong>время:</strong></td>
<td><?php echo get_post_meta($post->ID, 'время', 1); ?></td>
</tr>
</tbody>
</table>
<p><strong>О фильме: </strong><?php echo get_post_meta($post->ID, 'о фильме', 1); ?></p>
<div class="cleared"></div>
<?php if (is_search()) the_excerpt(); else the_content(__('Читать далее »', 'kubrick')); ?>
</div>
<div class="cleared"></div>
<?php $icons = array(); ?>
<?php if (!is_page() && !is_single()): ?><?php ob_start(); ?><?php comments_popup_link(__('Комментариев нет »', 'kubrick'), __('1 комментарий »', 'kubrick'), __('% комментариев »', 'kubrick'), '', __('Комментарии закрыты', 'kubrick') ); ?>
<?php $icons[] = ob_get_clean(); ?><?php endif; ?><?php if (0 != count($icons)): ?>
<div class="art-PostFooterIcons art-metadata-icons">
<?php echo implode(' | ', $icons); ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?> |
|
Может посоветуете лучшую структуру сайта если я не правильно начал.... помогите    /
0
|