-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
199 lines (159 loc) · 5.52 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
<?php
/**
* Enqueue custom scripts and styles function
*/
function load_custom_scripts_and_styles() {
wp_register_style('bootstrapcss', get_template_directory_uri() . '/assets/css/bootstrap.min.css');
wp_enqueue_style('bootstrapcss');
wp_register_style('headercss', get_template_directory_uri() . '/assets/css/header.css');
wp_enqueue_style('headercss');
wp_register_style('mediacss', get_template_directory_uri() . '/assets/css/media.css');
wp_enqueue_style('mediacss');
wp_register_style('stylecss', get_template_directory_uri() . '/assets/css/style.css');
wp_enqueue_style("stylecss");
wp_register_style('swipecss', get_template_directory_uri() . '/assets/css/swiper-bundle.min.css');
wp_enqueue_style('swipecss');
wp_register_script('bootstrapjs', get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js');
wp_enqueue_script('bootstrapjs');
wp_register_script('fileuploadjs', get_template_directory_uri() . '/assets/js/fileupload.js');
wp_enqueue_script('fileuploadjs');
wp_register_script('jqueryjs', get_template_directory_uri() . '/assets/js/jquery-3.6.3.min.js');
wp_enqueue_script('jqueryjs');
wp_register_script('jquery-minjs', get_template_directory_uri() . '/assets/js/jquery.min.js');
wp_enqueue_script('jquery-minjs');
wp_register_script('settingjs', get_template_directory_uri() . '/assets/js/setting.js');
wp_enqueue_script('settingjs');
wp_register_script('swipejs', get_template_directory_uri() . '/assets/js/swiper-bundle.min.js');
wp_enqueue_script('swipejs');
wp_register_script('pagejs', get_template_directory_uri() . '/assets/js/page.js');
wp_enqueue_script('pagejs');
wp_localize_script('pagejs', 'ajax_object', ['url' => admin_url('admin-ajax.php')]);
}
add_action('wp_enqueue_scripts', 'load_custom_scripts_and_styles');
/**
* Load more blogs function
* Function called by ajax
*/
function view_all_blogs() {
$get_blog_args = [
'post_type'=> "post",
'post_status' => "publish",
'offset' => 3
];
$get_all_blogs_query = new WP_Query($get_blog_args);
if ( $get_all_blogs_query->have_posts() ) {
while ( $get_all_blogs_query->have_posts() ) {
$get_all_blogs_query->the_post();
$thumbnail_url = get_the_post_thumbnail_url();
$post_time = get_the_date();
$title = get_the_title();
echo "<div class='col-lg-6'>";
get_template_part('template-part/card');
echo "</div>";
}
}
wp_reset_postdata();
exit;
}
add_action('wp_ajax_view_all_blogs', 'view_all_blogs');
add_action('wp_ajax_nopriv_view_all_blogs', 'view_all_blogs');
/**
* Register post type service
*/
function create_service_post_type() {
$labels = array(
'name' => 'Services',
'singular_name' => 'Service',
'add_new' => 'New Service',
'add_new_item' => 'Add New Service',
'edit_item' => 'Edit Service',
'new_item' => 'New Service',
'view_item' => 'View Service',
'search_items' => 'Search Service',
'not_found' => 'No Service Found',
'not_found_in_trash' => 'No Service found in Trash'
);
$args = array(
'labels' => $labels,
'has_archive' => true,
'public' => true,
'hierarchical' => false,
'rewrite' => array( 'slug' => 'service' ),
'taxonomies' => array( 'service_cat'),
);
register_post_type( 'service', $args );
}
add_action( 'init', 'create_service_post_type' );
/**
* Register taxanomy for service post type
*/
function create_service_category() {
register_taxonomy('service_cat', 'service', [
'label' => 'service_cat',
'public' => true,
'hierarchical' => true,
'rewrite' => false
]);
}
add_action('init', 'create_service_category');
/**
* Register REST API rout /post_info
*/
function post_info_rest_api() {
register_rest_route('wp/v2', '/post_info', array (
'methods' => 'GET',
'callback' => 'get_latest_post_info'
));
}
add_action('rest_api_init', 'post_info_rest_api');
/**
* Return the latest post
*/
function get_latest_post_info() {
$get_post_args = [
'post_type' => "post",
'post_status' => "publish",
'orderby' => "post_date",
'posts_per_page' => 3
];
$latest_post_query = new WP_Query($get_post_args);
return $latest_post_query;
}
/**
* custom widget area function
*/
function custom_widget_area() {
register_sidebar(array(
'name' => esc_html('custome_widget'),
'id' => 'custom_widget',
'description' => 'Custom Widget',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>'
));
}
add_action('widgets_init', 'custom_widget_area');
/**
* short code for get the 5 post title aplphabeticaaly
*/
function get_post_alphabatically() {
$get_post_args = [
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 5
];
$get_post_query = new WP_Query( $get_post_args );
$response = "";
if ( $get_post_query->have_posts() ) {
while ( $get_post_query->have_posts() ) {
$get_post_query->the_post();
$response .= "<h3>". get_the_title() ."</h3>";
}
}
return $response;
}
add_shortcode('alphabatically-post', 'get_post_alphabatically');
?>