-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
134 lines (104 loc) · 4.27 KB
/
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
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
<?php
/* Initialise child theme */
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
/* Disable block editor */
add_filter('use_block_editor_for_post', '__return_false', 10);
/* Disables the block editor from managing widgets */
add_filter( 'use_widgets_block_editor', '__return_false' );
/* Declaration of custom post type "glossary" */
function fngl_cpt_glossary()
{
$labels = array(
'name' => _x('Glossary', 'post type general name', 'wp-glossary'),
'singular_name' => _x('Glossary Item', 'post type singular name', 'wp-glossary'),
'menu_name' => _x('Glossary', 'admin menu', 'wp-glossary'),
'name_admin_bar' => _x('Glossary', 'add new on admin bar', 'wp-glossary'),
'add_new' => _x('Add New', 'wp-glossary'),
'add_new_item' => __('Add New Item', 'wp-glossary'),
'new_item' => __('New Item', 'wp-glossary'),
'edit_item' => __('Edit Item', 'wp-glossary'),
'view_item' => __('View Item', 'wp-glossary'),
'all_items' => __('All Items', 'wp-glossary'),
'search_items' => __('Search Items', 'wp-glossary'),
// 'parent_item_colon' => __('Parent glossary:', 'wp-glossary'),
'not_found' => __('No items found.', 'wp-glossary'),
'not_found_in_trash' => __('No items found in Trash.', 'wp-glossary'),
);
$support = array(
'title',
'editor',
'author',
// 'thumbnail',
// 'excerpt',
// 'custom-fields',
'comments',
'revisions',
// 'page-attributes',
);
$args = array(
// 'label' => _x('glossary', 'post type general name', 'wp-glossary'),
'labels' => $labels,
'menu_position' => 32,
'supports' => $support,
'public' => true,
'capability_type' => 'page',
// 'show_in_rest' => true,
'taxonomies' => array('glossary-category','post_tag'),
'hierarchical' => true,
'has_archive' => true,
);
register_post_type('glossary', $args);
}
add_action('init', 'fngl_cpt_glossary');
/* Show unlimited entries on glossary archives */
function fngl_get_all_glossary_posts( $query ) {
if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'glossary' ) ) {
$query->set( 'posts_per_page', '-1' );
// $query->set( 'orderby', 'title' ); // doesn't work due to multilingual titles
// $query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'fngl_get_all_glossary_posts' );
/* Register a 'glossary-category' taxonomy for post type 'glossary'. */
function fngl_cpt_glossary_cat() {
register_taxonomy( 'glossary-category', 'glossary', array(
'label' => __( 'Glossary Category', 'wp-glossary' ),
'rewrite' => array( 'slug' => 'glossary-category' ),
'hierarchical' => true,
) );
}
add_action( 'init', 'fngl_cpt_glossary_cat', 0 );
/* Add custom taxonomy 'glossary-category' column to CPT 'glossary' edit screen */
/* source: https://wordpress.stackexchange.com/questions/253640/adding-custom-columns-to-custom-post-types */
// Add the custom columns to the post type 'glossary'
add_filter( 'manage_glossary_posts_columns', 'set_custom_edit_glossary_columns' );
function set_custom_edit_glossary_columns($columns) {
unset( $columns['date'] );
$columns['glossary-category'] = __( 'Category', 'wp-glossary' );
// $columns['publisher'] = __( 'Publisher', 'your_text_domain' );
return $columns;
}
// Add the data to the custom columns for the post type 'glossary'
add_action( 'manage_glossary_posts_custom_column' , 'custom_glossary_column', 10, 2 );
function custom_glossary_column( $column, $post_id ) {
switch ( $column ) {
case 'glossary-category' :
$terms = get_the_term_list( $post_id , 'glossary-category' , '' , ',' , '' );
if ( is_string( $terms ) )
echo $terms;
else
_e( '- none -', 'wp-glossary' );
break;
// case 'publisher' :
// echo get_post_meta( $post_id , 'publisher' , true );
// break;
}
}
/* Last updated function */
function fngl_last_update(){
$updated_date = get_the_modified_time('Y-m-d');
echo '<span>last update </span>' . $updated_date;
}