-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
234 lines (190 loc) · 6.99 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
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
233
234
<?php
require get_theme_file_path('/inc/routes.php');
function eva_v1_supports()
{
add_theme_support('post-thumbnails');
}
add_action('after_setup_theme', 'eva_v1_supports');
function eva_v1_setup()
{
wp_enqueue_script('eva_v1_js', get_theme_file_uri('/build/index.js'), array(), '1.0', true);
wp_localize_script('eva_v1_js', 'evaV1Data', array(
'root_url' => get_site_url(),
));
wp_enqueue_style('eva_v1_main_styles', get_theme_file_uri('/build/index.css'));
}
add_action('wp_enqueue_scripts', 'eva_v1_setup');
function eva_v1_adjust_queries($query)
{
if (!is_admin() && is_post_type_archive('song') && is_main_query()) {
$query->set('order', 'DESC');
}
}
add_action('pre_get_posts', 'eva_v1_adjust_queries');
if (! function_exists('eva_v1_numeric_post_navigation')) {
/** Original Code:
* https://www.wpbeginner.com/wp-themes/how-to-add-numeric-pagination-in-your-wordpress-theme/
* */
function eva_v1_numeric_post_navigation(WP_Query $custom_query)
{
$user_locale = get_user_locale();
if (($user_locale == "en_US")) {
$previous_page_label = "« Previous Page";
$next_page_label = "Next Page »";
} else {
$previous_page_label = "« 이전 페이지";
$next_page_label = "다음 페이지 »";
}
if ($custom_query->is_singular()) {
return;
}
// Stop execution if there's only 1 page
if ($custom_query->max_num_pages <= 1) return;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$max_num_page = intval($custom_query->max_num_pages);
// Add current page to the array
if ($paged >= 1) {
$links[] = $paged;
}
// Add the pages around the current page to the array
if ($paged >= 3) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if (($paged + 2) <= $max_num_page) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
$output = "";
$output .= '<div class="page-navigation-sections">' . "\n";
// Previous Post Link
if ($paged > 1) {
$output .= sprintf('<div class="page-navigation-section flex-start">%s</div>' . "\n", get_previous_posts_link($previous_page_label));
}
// Start page navigation section
$output .= '<div class="page-navigation-section column-gap">';
// Link to first page.
if (! in_array(1, $links)) {
$class = ($paged == 1) ? 'class="active"' : '';
$output .= sprintf(
'<div %s><a href="%s">%s</a></div>' . "\n",
$class,
esc_url(get_pagenum_link(1)),
'1'
);
if (! in_array(2, $links))
$output .= '<div>…</div>';
}
// Link to current page, plus 2 pages in either direction if necessary.
sort($links);
foreach ((array) $links as $link) {
if ($paged == $link) {
$class = ' class="selected"';
$output .= sprintf('<div%s>%s</div>' . "\n", $class, $link);
} else {
$output .= sprintf('<div><a href="%s">%s</a></div>' . "\n", esc_url(get_pagenum_link($link)), $link);
}
}
// Link to last page.
if (! in_array($max_num_page, $links)) {
if (! in_array($max_num_page - 1, $links)) {
$output .= '<div>…</div>' . "\n";
}
$class = $paged == $max_num_page ? 'class="active"' : '';
$output .= sprintf('<div %s><a href="%s">%s</a></div>' . "\n", $class, esc_url(get_pagenum_link($max_num_page)), $max_num_page);
}
// Wrap page navigation section
$output .= '</div>';
// Next Post Link
if ($paged < $max_num_page) {
$output .= sprintf('<div class="page-navigation-section">%s</div>' . "\n", get_next_posts_link($next_page_label, $max_num_page));
}
$output .= '</div>' . "\n";
wp_reset_postdata();
echo $output;
}
}
if (! function_exists('eva_v1_reverse_post_navigation')) {
/** Original Code:
* https://gist.github.com/jaredchu/3e3bcb866240d1d32a3b4ae55905b135#file-the_reverse_post_navigation
* */
function eva_v1_reverse_post_navigation($args = array())
{
$args = wp_parse_args($args, array(
'prev_text' => '%title',
'next_text' => '%title',
'in_same_term' => false,
'excluded_terms' => '',
'taxonomy' => 'category',
'screen_reader_text' => __('Post navigation'),
));
$navigation = '';
$previous = get_next_post_link(
'<div class="nav-previous">%link</div>',
$args['prev_text'],
$args['in_same_term'],
$args['excluded_terms'],
$args['taxonomy']
);
$next = get_previous_post_link(
'<div class="nav-next">%link</div>',
$args['next_text'],
$args['in_same_term'],
$args['excluded_terms'],
$args['taxonomy']
);
// Only add markup if there's somewhere to navigate to.
if ($previous || $next) {
$navigation = _navigation_markup($previous . $next, 'post-navigation', $args['screen_reader_text']);
}
echo $navigation;
}
}
function eva_v1_songs_rewrite_rules()
{
add_rewrite_rule('^ko/songs/([0-9]+)/?$', 'index.php?song=$matches[1]', 'top');
}
add_action('init', 'eva_v1_songs_rewrite_rules', 1);
function eva_v1_register_locale()
{
$queue_list = array(
array("locale" => 'en_US', "directory" => get_template_directory() . '/locale/en_US.json'),
array("locale" => 'ko_KR', "directory" => get_template_directory() . '/locale/ko_KR.json')
);
global $eva_v1_locale;
$eva_v1_locale = array();
foreach ($queue_list as $item) {
$file_path = $item["directory"];
if (file_exists($file_path)) {
$json_data = file_get_contents($file_path);
$data = json_decode($json_data, true);
$eva_v1_locale[$item["locale"]] = $data;
}
}
}
add_action('init', 'eva_v1_register_locale');
/** Original Code:
* https://wordpress.stackexchange.com/questions/188332/override-default-wordpress-core-translation
*/
function cyb_filter_gettext($translated, $original, $domain)
{
$list = [
["답글 남기기", "댓글 남기기"],
];
for ($i = 0; $i < count($list); $i++) {
if ($translated == $list[$i][0]) {
$translated = $list[$i][1];
}
}
return $translated;
}
add_filter('gettext', 'cyb_filter_gettext', 10, 3);
if (! function_exists('eva_v1_get_korean_date')) {
function eva_v1_get_korean_date()
{
$year = get_the_time('Y');
$month = get_the_time('n');
$day = get_the_time('j');
return $year . '년 ' . $month . '월 ' . $day . '일';
}
}