-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
274 lines (244 loc) · 9.6 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
require_once get_theme_file_path( '/inc/tgm.php');
require_once get_theme_file_path( '/inc/attachments.php');
require_once get_theme_file_path( '/inc/admin-options.php');
require_once get_theme_file_path( '/inc/nav-menu-options.php');
//require_once get_theme_file_path( '/inc/Philosophpy_options.php');
require_once get_theme_file_path( '/inc/cf-metabox.php');
//require_once get_theme_file_path( '/widgets/social-icons-widget2.php');
if ( ! isset( $content_width ) ) $content_width = 960;
//check the version of css and js
if ( site_url() =='http://127.0.0.1/wordpress'){
define('VERSION', time() );
}else{
defined('VERSION',wp_get_theme()->get('Version'));
}
function philosophy_after_setup(){
load_theme_textdomain( 'philosophy',get_theme_file_path('/languages'));
add_theme_support('post-thumbnails');
add_theme_support('custom-logo');
add_theme_support('title-tag');
add_theme_support( 'automatic-feed-links' );
add_theme_support('html5',array('search-form','comment-list'));
add_theme_support('post-formats',array('image','gallery','quote','audio','video','link'));
add_editor_style('/assets/css/editor-style.css');
//Register Menu
register_nav_menu( 'topmenu',__('Top Menu','philosophy'));
register_nav_menus(array(
'footerleftmenu' =>__('Footer Left Menu','philosophy'),
'footermiddletmenu' =>__('Footer Middle Menu','philosophy'),
'footerrightmenu' =>__('Footer Right Menu','philosophy'),
));
add_image_size("philosophy-post-preview-square",400,400,true);
}
add_action('after_setup_theme','philosophy_after_setup');
function philosophy_assets(){
//stylesheets
wp_enqueue_style( 'fontaweseom-css',get_theme_file_uri('/assets/css/font-awesome/css/font-awesome.css'),null,VERSION);
wp_enqueue_style( 'fa5', 'https://use.fontawesome.com/releases/v5.13.0/css/all.css', array(), '5.13.0', 'all' );
wp_enqueue_style( 'fonts-css',get_theme_file_uri('/assets/css/fonts.css'),null,1.0);
wp_enqueue_style( 'base-css',get_theme_file_uri('/assets/css/base.css'),null,1.0);
wp_enqueue_style( 'vendor-css',get_theme_file_uri('/assets/css/vendor.css'),null,1.0);
wp_enqueue_style( 'main-css',get_theme_file_uri('/assets/css/main.css'),null,1.0);
wp_enqueue_style( 'philosophy-css',get_stylesheet_uri());
//scripts
wp_enqueue_script('modernizr-js',get_theme_file_uri('/assets/js/modernizr.js'),null,1.0);
wp_enqueue_script('pace-js',get_theme_file_uri('/assets/js/pace.min.js'),null,1.0);
wp_enqueue_script('plugins-js',get_theme_file_uri('/assets/js/plugins.js'),array('jquery'),1.0,true);
if ( is_singular() ) {
wp_enqueue_script( "comment-reply" );
}
wp_enqueue_script('main-js',get_theme_file_uri('/assets/js/main.js'),array('jquery'),1.0,true);
}
add_action( 'wp_enqueue_scripts','philosophy_assets');
function philosophy_pagination(){
global $wp_query;
$links= paginate_links(array(
'current' =>max(1,get_query_var( 'paged')),
'total' =>$wp_query->max_num_pages,
'type'=>'list',
'mid_size' => apply_filters('philosophy_pagination_mid_size',3)
));
$links = str_replace( "page-numbers", "pgn__num", $links );
$links = str_replace( "<ul class='pgn__num'>", "<ul>", $links );
$links = str_replace( "next pgn__num", "pgn__next", $links );
$links = str_replace( "prev pgn__num", "pgn__prev", $links );
echo wp_kses_post($links);
}
remove_action( 'term_description','wpautop');
/**
* Add about page sidebar.
*/
function philosophy_widgets() {
register_sidebar( array(
'name' => __( 'Header Social Icons', 'philosophy' ),
'id' => 'header-social',
'description' => __( 'Widgets in this area will be shown on home page header.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class="header_social %2$s">',
'after_widget' => '</div>',
'before_title' => '',
'after_title' => '',
) );
register_sidebar( array(
'name' => __( 'About Us Page', 'philosophy' ),
'id' => 'about-us',
'description' => __( 'Widgets in this area will be shown on about us page.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class="col-block %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="quarter-top-margin">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Contact Page Map Section', 'philosophy' ),
'id' => 'contact-map',
'description' => __( 'Widgets in this area will be shown on contact page.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '',
'after_title' => '',
) );
register_sidebar( array(
'name' => __( 'Contact Page Information Section', 'philosophy' ),
'id' => 'contact-info',
'description' => __( 'Widgets in this area will be shown on contact page.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class="col-six tab-full %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Before Footer Right Section', 'philosophy' ),
'id' => 'before-footer-right',
'description' => __( 'before footer right widget.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class=" %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( ' Footer Right Mail Section', 'philosophy' ),
'id' => 'footer-right-mail',
'description' => __( ' footer right mail widget.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class=" %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __( ' Footer Botoom Copyright', 'philosophy' ),
'id' => 'footer-bottom-copyright',
'description' => __( ' footer bottom copyright widget.', 'philosophy' ),
'before_widget' => '<div id="%1$s" class=" %2$s">',
'after_widget' => '</div>',
'before_title' => '',
'after_title' => '',
) );
}
add_action( 'widgets_init', 'philosophy_widgets' );
function philosophy_search_form(){
$homedir = home_url('/');
$label = __('Search for:','philosophy');
$button_label =__('Search','philosophy');
$post_type = <<<PT
<input type="hidden" name="post_type" value="post">
PT;
if(is_post_type_archive('book')){
$post_type = <<<PT
<input type="hidden" name="post_type" value="book">
PT;
}
$newform = <<<FORM
<form role="search" method="get" class="header__search-form" action="{$homedir}}">
<label>
<span class="hide-content">{$label}}</span>
<input type="search" class="search-field" placeholder="Type Keywords" value="" name="s" title="Search for:" autocomplete="off">
</label>
{$post_type}
<input type="submit" class="search-submit" value="{$button_label}">
</form>
FORM;
return $newform;
}
add_filter('get_search_form','philosophy_search_form');
function text_before_category_title1(){
echo "<p>Before Title 1</p>";
}
add_action('philosophy_before_category_title','text_before_category_title1',8);
function text_before_category_title2(){
echo "<p>used priority for Before Title 2</p>";
}
add_action('philosophy_before_category_title','text_before_category_title2',7);
function text_after_category_title(){
echo "<p>After Title</p>";
}
add_action('philosophy_after_category_title','text_after_category_title');
function text_after_category_title2(){
echo "<p>After Title 2</p>";
}
add_action('philosophy_after_category_title','text_after_category_title2',8);
function beginning_category_page($category_title){
if ('Music'==$category_title){
$visit_count = get_option('category_music');
$visit_count= $visit_count?$visit_count:0;
$visit_count++;
update_option('category_music',$visit_count);
}
}
add_action('philosophy_category_page','beginning_category_page');
function capital_text($param1, $param2){
return ucwords($param1).' → '.strtoupper($param2);
}
add_filter('philosophy_text','capital_text',10,2); //here 10 is priority and 2 is param numbers
function pgn_mid_size($size){
return 5;
}
add_filter('philosophy_pagination_mid_size','pgn_mid_size');
function philosophy_home_banner_class($class_name){
if ( is_home() ) {
return $class_name;
}else{
return '';
}
}
add_filter("philosophy_home_banner_class",'philosophy_home_banner_class');
remove_action('philosophy_after_category_title','text_after_category_title2',8);
//function for collection custom post type link/url
function philosophy_cpt_slug_link( $post_link, $id ) {
$pid = get_post($id);
if(is_object($pid) && 'chapter' ==get_post_type($id)){
$parent_post_id = get_field('parent_book');
$parent_post = get_post($parent_post_id);
if($parent_post){
$post_link = str_replace('%book%',$parent_post->post_name,$post_link);
}
}
// if(is_object($pid) && 'book'==get_post_type($pid)){
// $genre = wp_get_post_terms($pid->ID,'genre');
// if(is_array($genre) && count($genre)>0){
// $slug = $genre[0]->slug;
// $post_link = str_replace('%genre%',$slug,$post_link);
// }else{
// $slug = 'generic';
// $post_link = str_replace('%genre%',$slug,$post_link);
// }
// }
return $post_link;
}
add_filter( 'post_type_link', 'philosophy_cpt_slug_link', 1, 2 );
function philosophy_tags_heading_language($title){
if(is_post_type_archive('book') || is_tax('language')){
$title = __('Languages','philosophy');
}
return $title;
}
add_filter('philosophy_tags_heading','philosophy_tags_heading_language');
function philosophy_language_terms($language_terms){
if(is_post_type_archive('book') || is_tax('language')){
$language_terms = get_terms(array(
'taxonomy' =>'language',
'hide_empty' =>true,
));
}
return $language_terms;
}
add_filter('philosophy_tags_items','philosophy_language_terms');