This repository was archived by the owner on Aug 22, 2019. It is now read-only.
forked from castlegateit/cgit-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
232 lines (211 loc) · 6.26 KB
/
functions.php
File metadata and controls
232 lines (211 loc) · 6.26 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/**
* Zero functions and definitions
*
* This file contains the main settings for the Zero WordPress theme and
* provides various functions that can be used in the other template files. It
* is also used to activate support for featured images and to register menus
* and widget areas.
*/
/**
* Remove default actions
*
* By default, WordPress adds various elements to the <head> element using the
* wp_head hook. This removes the default elements. Other elements may also be
* removed from wp_head and wp_footer, but these may interfere with plugins.
*/
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
//remove_action('wp_head', 'locale_stylesheet');
//remove_action('wp_head', 'noindex');
//remove_action('wp_head', 'wp_enqueue_scripts');
//remove_action('wp_head', 'wp_print_head_scripts');
//remove_action('wp_head', 'wp_print_styles');
//remove_action('wp_head', 'wp_shortlink_wp_head');
//remove_action('wp_footer', 'wp_print_footer_scripts');
/**
* Add support for visual editor styles with editor-style.css
*/
add_editor_style();
/**
* Add featured image support
*/
add_theme_support('post-thumbnails');
/**
* Register sidebar
*
* This registers a single widget area. To register multiple widget areas, use
* the register_sidebars($number, $args) function, where $number is the number
* of sidebars and $args is an array of settings as below.
*/
register_sidebar(
array(
'name' => 'Sidebar',
'id' => 'sidebar',
'before_widget' => '<div id="%1$s" class="section %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
)
);
/**
* Register menu
*
* Multiple menus can be registered by adding to the associative array of menu
* locations.
*/
register_nav_menus(
array(
'nav' => __('Navigation')
)
);
/**
* Edit title tag
*
* Additional content, such as the site name and description, is added using
* the wp_title filter instead of adding manually in the header.php file. This
* allows the title to be manipulated by plugins.
*/
function z_edit_title($title, $sep, $seplocation) {
$output = '';
$name = get_bloginfo('name');
$description = get_bloginfo('description');
if(is_front_page() && $description) {
$name = "$name $sep $description";
}
if($seplocation == 'right') {
$output = $title . $name;
} else {
$output = $name . $title;
}
return $output;
}
add_filter('wp_title', 'z_edit_title', 10, 3);
/**
* Edit excerpt ellipsis
*/
function z_edit_excerpt_more($more) {
return ' …';
}
add_filter('excerpt_more', 'z_edit_excerpt_more');
/**
* Edit excerpt length
*/
function z_edit_excerpt_length($len) {
return 40;
}
add_filter('excerpt_length', 'z_edit_excerpt_length');
/**
* Function to return a post taxonomy
*
* This returns a list of categories, tags, or other taxonomy terms for a
* particular post, similar to the_category() or the_tags() but without the
* unpleasant rel attributes. By default, it lists the "category" taxonomy;
* use the "post_tag" taxonomy to list tags. This must be used within the
* loop.
*/
function z_taxon(
$taxon = 'category',
$before = '',
$sep = ', ',
$after = ''
) {
global $post;
$terms = get_the_terms($post->ID, $taxon);
$output = '';
if($terms) {
$output .= $before;
$list = array();
foreach($terms as $term) {
$link = get_term_link($term);
$name = $term->name;
$list[] = "<a href=\"$link\">$name</a>";
}
$output .= implode($sep, $list);
$output .= $after;
}
return $output;
}
/**
* Function to return a complete taxonomy list
*
* This returns a list of all the terms in a particular taxonomy in <li>
* elements, similar to wp_list_category(). By default, it lists the terms in
* the "category" taxonomy.
*/
function z_taxon_list($taxon = 'category') {
$terms = get_terms($taxon);
$output = '';
foreach($terms as $term) {
$link = get_term_link($term);
$name = $term->name;
$output .= "<li><a href=\"$link\">$name</a></li>";
}
return $output;
}
/**
* Function to return copyright date range based on content
*/
function z_copyright() {
global $wpdb;
$dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS first,
YEAR(max(post_date_gmt)) AS latest
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
if($dates) {
$first = $dates[0]->first;
$latest = $dates[0]->latest;
if($first == $latest) {
return $first;
} else {
return $first . '–' . $latest;
}
}
}
/**
* Function to return featured image URL
*/
function z_thumbnail_url() {
$image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
return $image[0];
}
/**
* Function to generate comment output
*
* This defines a basic comment format and is used as a callback in
* comments.php. Avatars, edit links, and reply links can also be added. The
* comment closing tag is omitted here and inserted automatically by WordPress.
*/
function z_comment($comment, $args, $depth) {
// Get comment object
$GLOBALS['comment'] = $comment;
// Get current comment data
$author = get_comment_author_link();
$class_name = implode(' ', get_comment_class());
$date = get_comment_date();
$id = get_comment_ID();
$link = get_comment_link($comment->comment_ID);
$time = get_comment_time();
//$avatar = get_avatar($comment, 40);
//$edit = get_edit_comment_link('Edit', '<p class="edit">', '</p>');
//$reply = get_comment_reply_link();
// Generate comment output
$output = "<li class=\"$class_name\" id=\"comment-$id\">";
$output .= "<h3>$author on <a href=\"$link\">$date at $time</a></h3>";
if($comment->comment_approved) {
$output .= get_comment_text();
} else {
$output .= '<p>Your comment is awaiting moderation.</p>';
}
echo $output;
}