-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-projetos.php
114 lines (102 loc) · 3.7 KB
/
custom-projetos.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
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
<?php
/**
* Adicionamos uma acção no inicio do carregamento do WordPress
* através da função add_action( 'init' )
*/
add_action( 'init', 'create_post_type_projetos' );
/**
* Esta é a função que é chamada pelo add_action()
*/
function create_post_type_projetos() {
/**
* Labels customizados para o tipo de post
*/
$labels = array(
'name' => _x('Projetos', 'post type general name'),
'singular_name' => _x('Projeto', 'post type singular name'),
'add_new' => _x('Novo Projeto', 'projeto'),
'add_new_item' => __('Novo Projeto'),
'edit_item' => __('Editar Projeto'),
'new_item' => __('Novo Projeto'),
'all_items' => __('Todos Projetos'),
'view_item' => __('Ver Projeto'),
'search_items' => __('Procurar Projetos'),
'not_found' => __('Nenhum projetos encontrado'),
'not_found_in_trash' => __('Nenhum projeto encontrado no lixo'),
'parent_item_colon' => '',
'menu_name' => 'Projetos'
);
/**
* Registamos o tipo de post projetos através desta função
* passando-lhe os labels e parâmetros de controlo.
*/
register_post_type( 'projetos', array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'has_archive' => 'projetos',
'rewrite' => array(
'slug' => 'projeto',
'with_front' => false,
),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt','comments')
)
);
/**
* Registamos a categoria de projetos para o tipo de post projetos
*/
register_taxonomy( 'projetos_category', array( 'projetos' ), array(
'hierarchical' => true,
'label' => __( 'Projetos Category' ),
'labels' => array( // Labels customizadas
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Categorias' ),
),
'show_ui' => true,
'show_in_tag_cloud' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'projetos/categories',
'with_front' => false,
),
)
);
/**
* Esta função associa tipos de categorias com tipos de posts.
* Aqui associamos as tags ao tipo de post projetos.
*/
register_taxonomy_for_object_type( 'tags', 'projetos' );
}
// Adiciona a coluna Categorias ao Custom Post Type Projetos
add_filter( 'manage_projetos_posts_columns', 'ilc_cpt_columns' );
add_action('manage_projetos_posts_custom_column', 'ilc_cpt_custom_column', 10, 2);
function ilc_cpt_columns($defaults) {
$defaults['projetos_category'] = 'Categoria';
return $defaults;
}
function ilc_cpt_custom_column($column_name, $post_id) {
$taxonomy = $column_name;
$post_type = get_post_type($post_id);
$terms = get_the_terms($post_id, $taxonomy);
if ( !empty($terms) ) {
foreach ( $terms as $term )
$post_terms[] = "<a href='edit.php?post_type={$post_type}&{$taxonomy}={$term->slug}'> " . esc_html(sanitize_term_field('name', $term->name, $term->term_id, $taxonomy, 'edit')) . "</a>";
echo join( ', ', $post_terms );
}
else echo '<i>No terms.</i>';
}