-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-portfolio.php
125 lines (112 loc) · 3.51 KB
/
custom-portfolio.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
115
116
117
118
119
120
121
122
123
124
125
<?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_portfolios' );
/** * Esta é a função que é chamada pelo add_action() */
function create_post_type_portfolios() {
/** * Labels customizados para o tipo de post */
$labels = array(
'name' => _x('Portfolio', 'post type general name'),
'singular_name' => _x('Portfolio', 'post type singular name'),
'add_new' => _x('Novo Portfolio', 'portfolio'),
'add_new_item' => __('Novo Portfolio'),
'edit_item' => __('Editar Portfolio'),
'new_item' => __('Novo Portfolio'),
'all_items' => __('Ver Todos'),
'view_item' => __('Ver Portfolio'),
'search_items' => __('Procurar Projetos'),
'not_found' => __('Nenhum portfolio encontrado'),
'not_found_in_trash' => __('Nenhum portfolio encontrado no lixo'),
'parent_item_colon' => '',
'menu_name' => 'Portfolio'
);
/** * Registamos o tipo de post portfolios através desta função
* passando-lhe os labels e parâmetros de controlo.
*/
register_post_type( 'portfolio', array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'has_archive' => 'portfolio',
'query_var' => true,
'rewrite' => array(
'slug' => 'portfolio',
'with_front' => false,
),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array('title','editor','page-attributes','thumbnail','revisions')
) );
flush_rewrite_rules();}
register_taxonomy(
"area",
"portfolio",
array(
"label" => "Areas",
"singular_label" => "Area",
"rewrite" => true,
"hierarchical" => true
)
);
// Adiciona a coluna Areas ao Custom Post Type Projetos
add_filter( 'manage_portfolio_posts_columns', 'ilc_cpt_columns' );
add_action('manage_portfolio_posts_custom_column', 'ilc_cpt_custom_column', 10, 2);
function ilc_cpt_columns($defaults) {
$defaults['area'] = 'Area';
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 )
if (is_object($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>Nenhuma area.</i>';
}
add_action( 'wp_ajax_portfolio_query', 'portfolio_query_ajax' );
add_action( 'wp_ajax_nopriv_portfolio_query', 'portfolio_query_ajax' );
function portfolio_query_ajax() {
$area = $_POST['area'];
// WP_Query arguments
if($area == 'false'){
$args = array (
'post_type' => 'portfolio',
'posts_per_page' => -1,
'post_status' => array('publish'),
'post_parent' => 0,
);
}
else{
$args = array (
'post_type' => 'portfolio',
'post_parent' => 0,
'posts_per_page' => -1,
'post_status' => array('publish'),
'area' => $area,
);
}
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
get_template_part('content','portfolio');
}
}
// Restore original Post Data
wp_reset_postdata();
wp_die();
}
?>