· 7 years ago · Feb 27, 2018, 09:08 AM
1<?php
2/* Theme Name : Awada
3 * Theme Core Functions and Codes
4 */
5define('RWMB_DIR', get_template_directory() . '/inc/meta-box/');
6define('RWMB_URL', get_template_directory_uri() . '/inc/meta-box/');
7require get_template_directory() . '/functions/menu/default_menu_walker.php';
8require get_template_directory() . '/functions/menu/awada_nav_walker.php';
9require get_template_directory() . '/functions/custom/cpts.php';
10require get_template_directory() . '/functions/custom/contact-widgets.php';
11require get_template_directory() . '/functions/custom/recent-posts.php';
12require get_template_directory() . '/functions/custom/flickr-widget.php';
13require get_template_directory() . '/functions/scripts/scripts.php';
14require get_template_directory() . '/functions/custom/image_crop.php';
15require get_template_directory() . '/functions/shortcodes/shortcodes.php';
16require get_template_directory() . '/functions/phpmailer/sendemail.php';
17require RWMB_DIR . '/meta-box.php';
18require get_template_directory() . '/functions/custom/metabox.php';
19require_once get_template_directory() . '/inc/class-tgm-plugin-activation.php';
20require get_template_directory() . '/inc/theme-option/framework.php';
21require get_template_directory() . '/inc/theme-option/option-panel.php';
22require_once dirname(__FILE__) . '/inc/theme-option/options/css/reduxCss.php';
23add_action('after_setup_theme', 'awada_theme_setup');
24require_once dirname(__FILE__) . '/default.php';
25global $awada_theme_options;
26if (array_key_exists('twitter', $awada_theme_options['homepage_layout']['Enabled'])) {
27 require get_template_directory() . '/functions/scripts/twitteroauth/twitteroauth.php';
28}
29
30function awada_theme_setup()
31{
32 global $content_width;
33 //content width
34 if (!isset($content_width)) {
35 $content_width = 1068;
36 }
37 //px
38 if (is_page_template('about-us-two.php')) {
39 $content_width = 100;
40 }
41 //supports featured image
42 add_theme_support('post-thumbnails');
43 load_theme_textdomain('awada', get_template_directory() . '/lang');
44 // This theme uses wp_nav_menu() in one location.
45 register_nav_menu('primary', __('Primary Menu', 'awada'));
46 register_nav_menu('secondary', __('Secondary Menu', 'awada'));
47 // theme support
48 add_editor_style();
49 $args = array('default-color' => '#ffffff');
50 add_theme_support('custom-background', $args);
51 add_theme_support('custom-header');
52 add_theme_support('automatic-feed-links');
53 add_theme_support('woocommerce');
54 add_theme_support('wc-product-gallery-zoom');
55 add_theme_support('wc-product-gallery-lightbox');
56 add_theme_support('wc-product-gallery-slider');
57 add_theme_support('title-tag');
58 add_theme_support('custom-logo', array(
59 'height' => 50,
60 'width' => 150,
61 'flex-height' => true,
62 'flex-width' => true,
63 ));
64}
65// Read more tag to formatting in blog page
66function awada_content_more($read_more)
67{
68 return '<div class=""><a class="main-button" href="' . get_permalink() . '">' . __('Read More', 'awada') . '<i class="fa fa-angle-right"></i></a></div>';
69}
70add_filter('the_content_more_link', 'awada_content_more');
71// Replaces the excerpt "more" text by a link
72function awada_excerpt_more($more)
73{
74 return '<a href="' . get_permalink() . '" class="readmore">' . __('Read More...', 'awada') . '</a>';
75}
76add_filter('excerpt_more', 'awada_excerpt_more');
77/*
78 * Awada widget area
79 */
80add_action('widgets_init', 'awada_widget');
81function awada_widget()
82{
83 /*sidebar*/
84 global $awada_theme_options;
85 $col = 12 / (int) $awada_theme_options['footer_layout'];
86 register_sidebar(array(
87 'name' => __('Primary Sidebar Widget Area', 'awada'),
88 'id' => 'primary-sidebar',
89 'description' => __('Primary sidebar widget area', 'awada'),
90 'before_widget' => '<div id="%1$s" class="widget %2$s">',
91 'after_widget' => '</div>',
92 'before_title' => '<div class="title"><h2>',
93 'after_title' => '</h2></div>',
94 ));
95 register_sidebar(array(
96 'name' => __('Secondary Sidebar Widget Area', 'awada'),
97 'id' => 'secondary-sidebar',
98 'description' => __('Secondary sidebar widget area', 'awada'),
99 'before_widget' => '<div id="%1$s" class="widget %2$s">',
100 'after_widget' => '</div>',
101 'before_title' => '<div class="title"><h3>',
102 'after_title' => '</h3></div>',
103 ));
104 register_sidebar(array(
105 'name' => __('Footer Widget Area', 'awada'),
106 'id' => 'footer-widget',
107 'description' => __('Footer widget area', 'awada'),
108 'before_widget' => '<div class="col-lg-' . $col . ' col-md-' . $col . ' col-sm-6 col-xs-12"><div id="%1$s" class="widget %2$s">',
109 'after_widget' => '</div></div>',
110 'before_title' => '<div class="title"><h3>',
111 'after_title' => '</h3></div>',
112 ));
113}
114/* Breadcrumbs */
115function awada_breadcrumbs()
116{
117 $delimiter = '<i class="fa fa-chevron-circle-right breadcrumbs_space"></i>';
118 $home = __('Home', 'awada'); // text for the 'Home' link
119 $before = ''; // tag before the current crumb
120 $after = ''; // tag after the current crumb
121 echo '<ul class="breadcrumb pull-right">';
122 global $post;
123 $homeLink = home_url();
124 if (is_front_page()) {
125 echo '<li><a href="' . $homeLink . '">' . $home . '</a>';
126 } else {
127 echo '<li><a href="' . $homeLink . '">' . $home . '</a>' . $delimiter;
128 }
129
130 if (is_category()) {
131 global $wp_query;
132 $cat_obj = $wp_query->get_queried_object();
133 $thisCat = $cat_obj->term_id;
134 $thisCat = get_category($thisCat);
135 $parentCat = get_category($thisCat->parent);
136 if ($thisCat->parent != 0) {
137 echo (get_category_parents($parentCat, true, ' ' . $delimiter . '</li> '));
138 }
139
140 echo $before . _e("Category ", 'awada') . ' ' . single_cat_title($delimiter, false) . '' . $after;
141 } elseif (is_day()) {
142 echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter . '</li>';
143 echo '<li><a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter;
144 echo $before . get_the_time('d') . '</li>';
145 } elseif (is_month()) {
146 echo '<li><a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a>' . $delimiter;
147 echo $before . get_the_time('F') . '</li>';
148 } elseif (is_year()) {
149 echo $before . get_the_time('Y') . '</li>';
150 } elseif (is_single() && !is_attachment()) {
151 if (get_post_type() != 'post') {
152 $post_type = get_post_type_object(get_post_type());
153 if (get_post_type() == "product") {
154 $shop_page_url = get_permalink(wc_get_page_id('shop'));
155 echo '<li><a href="' . $shop_page_url . '">' . $post_type->labels->singular_name . '</a> ' . $delimiter;
156 } else {
157 $slug = $post_type->rewrite;
158 echo '<li><a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $slug['slug'] . '</a> ' . $delimiter;
159 }
160 echo $before . get_the_title() . '</li>';
161 } else {
162 $cat = get_the_category();
163 $cat = $cat[0];
164 //echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
165 echo $before . get_the_title() . '</li>';
166 }
167 } elseif (class_exists('woocommerce') && is_shop()) {
168 echo $before . __('Shop', 'awada') . $after;
169
170 } elseif (!is_single() && !is_page() && get_post_type() != 'post') {
171 $post_type = get_post_type_object(get_post_type());
172 if ($post_type == null) {
173 echo $before . __('Nothing Found', 'awada') . $after;
174 } else {
175 $slug = $post_type->rewrite;
176 echo $before . $slug['slug'] . $after;
177 }
178 } elseif (is_attachment()) {
179 $parent = get_post($post->post_parent);
180 $cat = get_the_category($parent->ID);
181 $cat = $cat[0];
182 echo get_category_parents($cat, true, ' ' . $delimiter . ' ');
183 echo '<li><a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a>' . $delimiter;
184 echo $before . get_the_title() . $after;
185 } elseif (is_page() && !$post->post_parent) {
186 echo $before . get_the_title() . $after;
187 } elseif (is_page() && $post->post_parent) {
188 $parent_id = $post->post_parent;
189 $breadcrumbs = array();
190 while ($parent_id) {
191 $page = get_page($parent_id);
192 $breadcrumbs[] = '<li><a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a></li>';
193 $parent_id = $page->post_parent;
194 }
195 $breadcrumbs = array_reverse($breadcrumbs);
196 foreach ($breadcrumbs as $crumb) {
197 echo $crumb . ' ' . $delimiter . ' ';
198 }
199
200 echo $before . get_the_title() . $after;
201 } elseif (is_search()) {
202 echo $before . _e("Search results for ", 'awada') . get_search_query() . '"' . $after;
203
204 } elseif (is_tag()) {
205 echo $before . _e('Tag ', 'awada') . single_tag_title($delimiter, false) . $after;
206 } elseif (is_author()) {
207 global $author;
208 $userdata = get_userdata($author);
209 echo $before . _e("Articles posted by: ", 'awada') . $userdata->display_name . $after;
210 } elseif (is_404()) {
211 echo $before . _e("Error 404 ", 'awada') . $after;
212 } elseif (single_post_title()) {
213 echo $before . single_post_title() . $after;
214 }
215 echo '</ul>';
216}
217
218//Blog PAGINATION
219function awada_pagination($pages = '', $range = 2)
220{
221 $showitems = ($range * 2) + 1;
222 global $paged;
223 if (empty($paged)) {
224 $paged = 1;
225 }
226
227 if ($pages == '') {
228 global $wp_query;
229 $pages = $wp_query->max_num_pages;
230 if (!$pages) {
231 $pages = 1;
232 }
233 }
234 if (1 != $pages) {
235 echo "<div class='pagination_wrapper'><ul class='pagination'>";
236 if ($paged > 2 && $paged > $range + 1 && $showitems < $pages) {
237 echo "<li><a href='" . get_pagenum_link(1) . "'>«</a></li>";
238 }
239
240 if ($paged > 1 && $showitems < $pages) {
241 echo "<li><a href='" . get_pagenum_link($paged - 1) . "'>‹</a></li>";
242 }
243
244 for ($i = 1; $i <= $pages; $i++) {
245 if (1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems)) {
246 echo ($paged == $i) ? "<li class='active'><a>" . $i . "</a></li>" : "<li><a href='" . get_pagenum_link($i) . "'>" . $i . "</a></li>";
247 }
248 }
249 if ($paged < $pages && $showitems < $pages) {
250 echo "<li><a href='" . get_pagenum_link($paged + 1) . "'>›</a></li>";
251 }
252
253 if ($paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages) {
254 echo "<li><a href='" . get_pagenum_link($pages) . "'>»</a></li>";
255 }
256
257 echo "</ul></div>";
258 }
259}
260/*** Post pagination ***/
261function awada_pagination_link()
262{?>
263 <div class="next_prev text-center">
264 <ul class="pager">
265 <li class="previous"><?php previous_post_link('%link', '« Older');?></li>
266 <li class="next"><?php next_post_link('%link', 'Newer »');?></li>
267 </ul>
268 </div><?php
269}
270// Comment Function
271function awada_comments($comments, $args, $depth)
272{
273 $GLOBALS['comment'] = $comments;
274 extract($args, EXTR_SKIP);
275 if ('div' == $args['style']) {
276 $add_below = 'comment';
277 } else {
278 $add_below = 'div-comment';
279 }
280 ?>
281 <li <?php comment_class(empty($args['has_children']) ? '' : 'parent')?> id="comment-<?php comment_ID()?>">
282 <article class="comment">
283 <?php if ($args['avatar_size'] != 0) {
284 echo get_avatar($comments, $args['avatar_size'], null, null, $arrayName = array('class' => 'img-circle comment-avatar'));
285 }
286 ?>
287 <div class="comment-content">
288 <h4 class="comment-author">
289 <?php printf('%s', get_comment_author());?><small class="comment-meta"><?php printf(__('%1$s at %2$s', 'awada'), get_comment_date(), get_comment_time());?></small>
290 <span class="comment-reply"><?php comment_reply_link(array_merge($args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'])));?></span>
291 </h4><?php
292if ($comments->comment_approved == '0') {?>
293 <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'awada');?></em><br/>
294 </div><?php } else {comment_text();}?>
295 </div>
296 </article><!-- End .comment -->
297<?php
298}
299add_filter('comment_reply_link', 'awada_replace_reply_link_class');
300function awada_replace_reply_link_class($class)
301{
302 $class = str_replace("class='comment-reply-link", "class='comment-reply btn btn-sm btn-primary", $class);
303 return $class;
304}
305
306add_filter('get_avatar', 'change_avatar_css');
307function change_avatar_css($class)
308{
309 $class = str_replace("class='avatar", "class='img-circle alignleft ", $class);
310 return $class;
311}
312// get taxonomies terms links
313function custom_taxonomies_terms_links()
314{
315 // get post by post id
316 global $post;
317 $post = get_post($post->ID);
318 // get post type by post
319 $post_type = $post->post_type;
320 // get post type taxonomies
321 $taxonomies = get_object_taxonomies($post_type, 'objects');
322 $out = array();
323 foreach ($taxonomies as $taxonomy_slug => $taxonomy) {
324 // get the terms related to post
325 $terms = get_the_terms($post->ID, $taxonomy_slug);
326 if (!empty($terms)) {
327 foreach ($terms as $term) {
328 $out[] =
329 ' <a href="'
330 . get_term_link($term->slug, $taxonomy_slug) . '">'
331 . $term->name
332 . "</a>";
333 }
334 }
335 }
336 return implode(', ', $out);
337}
338//maintenance enable function 'template redirect'
339function maintenance_template_redirect()
340{
341 global $awada_theme_options;
342 if (isset($awada_theme_options['enable_maintenance_mode']) && $awada_theme_options['enable_maintenance_mode']) {
343 if (!is_feed()) {
344 //if user not login page is redirect on coming soon template page
345 if (!is_user_logged_in()) {
346
347 $file = get_template_directory() . '/inc/theme-option/coming-soon.php';
348 include $file;
349 exit();
350 }
351 }
352 //if user is log-in then we check role.
353 if (is_user_logged_in()) {
354 //get logined in user role
355 global $current_user;
356 get_currentuserinfo();
357 $LoggedInUserID = $current_user->ID;
358 $UserData = get_userdata($LoggedInUserID);
359 //if user role not 'administrator' redirect him to message page
360 if ($UserData->roles[0] != "administrator") {
361 if (!is_feed()) {
362 $file = get_template_directory() . '/inc/theme-option/coming-soon.php';
363 exit();
364 }
365 }
366 }
367 }
368}
369//add action to call function maintenance_template_redirect
370add_action('template_redirect', 'maintenance_template_redirect');
371
372add_filter('embed_defaults', 'change_embed_size');
373function change_embed_size()
374{
375 // Adjust values
376 return array('width' => 100, 'height' => 100);
377}
378/* Twitter feed */
379function getTwitterFeed()
380{
381 global $awada_theme_options;
382
383 $twitteruser = "";
384 $notweets = $awada_theme_options['twitter_feed_count'];
385 $consumerkey = $awada_theme_options['twitter_consumer_key'];
386 $consumersecret = $awada_theme_options['twitter_consumer_secret'];
387 $accesstoken = $awada_theme_options['twitter_access_token'];
388 $accesstokensecret = $awada_theme_options['twitter_access_token_secret'];
389
390 function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret)
391 {
392 $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
393 return $connection;
394 }
395
396 $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
397
398 $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets);
399
400 return json_encode($tweets);
401}
402/* Twitter Timing */
403function humanTiming($time)
404{
405 $time = strtotime($time);
406 $time = time() - $time; // to get the time since that moment
407 $time = ($time < 1) ? 1 : $time;
408 $tokens = array(
409 31536000 => 'year',
410 2592000 => 'month',
411 604800 => 'week',
412 86400 => 'day',
413 3600 => 'hour',
414 60 => 'minute',
415 1 => 'second',
416 );
417
418 foreach ($tokens as $unit => $text) {
419 if ($time < $unit) {
420 continue;
421 }
422
423 $numberOfUnits = floor($time / $unit);
424 return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : '');
425 }
426}
427
428/* TGMPA register */
429add_action('tgmpa_register', 'awada_register_required_plugins');
430function awada_register_required_plugins()
431{
432 /*
433 * Array of plugin arrays. Required keys are name and slug.
434 * If the source is NOT from the .org repo, then source is also required.
435 */
436 $plugins = array(
437 // This is an example of how to include a plugin bundled with a theme.
438 array(
439 'name' => 'WooCommerce Grid / List toggle', // The plugin name.
440 'slug' => 'woocommerce-grid-list-toggle', // The plugin slug (typically the folder name).
441 'required' => false, // If false, the plugin is only 'recommended' instead of required.
442 ),
443
444 array(
445 'name' => 'YITH WooCommerce Compare', // The plugin name.
446 'slug' => 'yith-woocommerce-compare', // The plugin slug (typically the folder name).
447 'required' => false, // If false, the plugin is only 'recommended' instead of required.
448 ),
449 array(
450 'name' => 'YITH WooCommerce Wishlist', // The plugin name.
451 'slug' => 'yith-woocommerce-wishlist', // The plugin slug (typically the folder name).
452 'required' => false, // If false, the plugin is only 'recommended' instead of required.
453 ),
454 );
455 $config = array(
456 'id' => 'awada', // Unique ID for hashing notices for multiple instances of awada.
457 'default_path' => '', // Default absolute path to bundled plugins.
458 'menu' => 'awada-install-plugins', // Menu slug.
459 'parent_slug' => 'themes.php', // Parent menu slug.
460 'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
461 'has_notices' => true, // Show admin notices or not.
462 'dismissable' => true, // If false, a user cannot dismiss the nag message.
463 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
464 'is_automatic' => false, // Automatically activate plugins after installation or not.
465 'message' => __('If you are using this theme for your woocommerce shop, install recommended plugins for better user experience.', 'awada'), // Message to output right before the plugins table.
466 );
467 awada($plugins, $config);
468}
469/* woocommerce support */
470remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
471remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
472add_action('woocommerce_before_main_content', 'awada_theme_wrapper_start', 10);
473add_action('woocommerce_after_main_content', 'awada_theme_wrapper_end', 10);
474function awada_theme_wrapper_start()
475{
476 global $awada_theme_options;
477 $woosidebar = $awada_theme_options['woosidebar'];
478 if(is_shop()){
479 $col = '12';
480 }else{
481 $col = $woosidebar == 'full' ? '12' : '9';
482 }
483 get_template_part('breadcrumbs');?>
484 <section class="blog-wrapper">
485 <div class="container">
486 <?php if ($woosidebar == 'left' ) {do_action('woocommerce_sidebar');}?>
487 <div id="content" class="shop_wrapper col-lg-<?php echo esc_attr($col); ?> col-md-<?php echo esc_attr($col); ?> col-sm-12 col-xs-12">
488 <div class="general_row"><?php
489}
490function awada_theme_wrapper_end()
491{
492 global $awada_theme_options;
493 $woosidebar = $awada_theme_options['woosidebar'];?>
494 </div>
495 </div>
496
497 <?php if($woosidebar == 'right' ) {do_action('woocommerce_sidebar');}?>
498 </div>
499</section>
500<?php }
501add_action( 'wp', 'bbloomer_remove_sidebar_product_pages' );
502
503function bbloomer_remove_sidebar_product_pages() {
504 if ( is_shop() ) {
505 remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
506 }
507}
508/* Get Video Type */
509function videoType($url)
510{
511 if (strpos($url, 'youtube') > 0) {
512 $pos = strrpos($url, 'v=');
513 $str = substr($url, $pos + 2);
514 return 'https://www.youtube.com/embed/' . $str;
515 } elseif (strpos($url, 'vimeo') > 0) {
516 $pos = strrpos($url, '/');
517 $str = substr($url, $pos + 1);
518 return 'https://player.vimeo.com/video/' . $str;
519 }
520}
521function videoType1($url)
522{
523 if (strpos($url, 'youtube') > 0) {
524 return 'youtube';
525 } elseif (strpos($url, 'vimeo') > 0) {
526 return 'vimeo';
527 }
528}
529/* function awada_custom_excerpt_length( $length ) {
530return 20;
531}
532add_filter( 'excerpt_length', 'awada_custom_excerpt_length', 999 ); */
533
534function awada_excerpt($limit)
535{
536 $excerpt = explode(' ', get_the_excerpt(), $limit);
537 if (count($excerpt) >= $limit) {
538 array_pop($excerpt);
539 $excerpt = implode(" ", $excerpt) . '<a href="' . get_permalink() . '" class="readmore">' . __('Read More...', 'awada') . '</a>';
540 } else {
541 $excerpt = implode(" ", $excerpt);
542 }
543 $excerpt = preg_replace('`[[^]]*]`', '', $excerpt);
544 return $excerpt;
545}
546
547/* function awada_content($limit) {
548$content = explode(' ', get_the_content(), $limit);
549if (count($content)>=$limit) {
550array_pop($content);
551$content = implode(" ",$content).'...';
552} else {
553$content = implode(" ",$content);
554}
555$content = preg_replace('/[.+]/','', $content);
556$content = apply_filters('the_content', $content);
557$content = str_replace(']]>', ']]>', $content);
558return $content;
559} */
560
561add_filter('get_product_search_form', 'awada_custom_product_searchform');
562
563/**
564 * woo_custom_product_searchform
565 *
566 * @access public
567 * @since 1.0
568 * @return void
569 */
570function awada_custom_product_searchform($form)
571{
572
573 $form = '<form action="' . esc_url(home_url('/')) . '" autocomplete="off" role="search" method="get" class="newsletter_form search_form">
574 <input type="text" class="form-control search-field" placeholder="' . esc_attr__('Search Product...', 'awada') . '" value="' . get_search_query() . '" id="s" name="s">
575 <input type="hidden" name="post_type" value="product">
576 </form>';
577 return $form;
578
579}
580/**
581 * woocommerce_version_check
582 *
583 * @access public
584 * @since 1.2.2
585 * @return boolean
586 */
587function awada_woocommerce_version_check($version = '3.0')
588{
589 if (class_exists('WooCommerce')) {
590 global $woocommerce;
591 if (version_compare($woocommerce->version, $version, ">=")) {
592 return true;
593 }
594 }
595 return false;
596}
597
598/* Ajax Load Moe posts */
599add_action('wp_ajax_nopriv_awada_more_post_ajax', 'awada_more_post_ajax');
600add_action('wp_ajax_awada_more_post_ajax', 'awada_more_post_ajax');
601
602if (!function_exists('awada_more_post_ajax')) {
603 function awada_more_post_ajax()
604 {
605
606 $awada_theme_options = awada_theme_options();
607 $ppp = (isset($_POST['ppp'])) ? $_POST['ppp'] : 3;
608 $offset = (isset($_POST['offset'])) ? $_POST['offset'] : 0;
609
610 $args = array(
611 'post_type' => 'post',
612 'posts_per_page' => $ppp,
613 'offset' => $offset,
614 );
615 if (isset($awada_theme_options['home_post_cat']) && !empty($awada_theme_options['home_post_cat'])) {
616 $args['category__in'] = $awada_theme_options['home_post_cat'];
617 }
618
619 $loop = new WP_Query($args);
620 $out = '';
621 $i = 1;
622 if ($loop->have_posts()):
623 while ($loop->have_posts()):
624 $loop->the_post();
625 $out .= '<div class="col-lg-4 grid-item">
626 <div id="post-' . get_the_ID() . '" class="blog-carousel">
627 <div class="content_entry">';
628 $img_class = array('class' => 'img-responsive full-width');
629 $attachments = rwmb_meta('awada_post_gallery', 'type=image&size=' . 'awada_blog_home_thumb', get_the_ID());
630 if((has_post_thumbnail() && get_post_meta(get_the_ID(), 'awada_video_post_url', true)) || $attachments ){
631 $out .= '<div class="flexslider">
632 <ul class="slides">';
633 if ($attachments) {
634 foreach ($attachments as $attachment) {
635 $out .= '<li><img src="' . esc_url($attachment['url']) . '" class="img-responsive full-width" alt="' . $attachment['alt'] . '"></li>';
636 }
637 }
638 if (get_post_meta(get_the_ID(), 'awada_video_post_url', true) != "") {
639 $out .= '<li>';
640 $url = get_post_meta(get_the_ID(), 'awada_video_post_url', true);
641 if ($awada_theme_options['blog_video_popup_enable'] == 'true') {
642 $url1 = videoType1($url);
643 if ($url1 == 'youtube') {
644 $parts = parse_url($url);
645 parse_str($parts['query'], $query);
646 $video_id = $query['v'];
647 $out .= '<a href="' . esc_url($url) . '" data-gal="prettyPhoto[product-gallery]" title="' . the_title_attribute('echo=0') . '"><img src="https://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg" alt="' . the_title_attribute('echo=0') . '"/></a>';
648 } else if ($url1 == 'vimeo') {
649 $imgid = (int) substr(parse_url($url, PHP_URL_PATH), 1);
650 $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));
651 $out .= '<a href="' . esc_url($url) . '" data-gal="prettyPhoto[product-gallery]" title="' . the_title_attribute('echo=0') . '"><img src="https://i.vimeocdn.com/video/' . $hash[0]['thumbnail_medium'] . '" alt="' . the_title_attribute('echo=0') . '"/></a>';
652 }
653 } else {
654 $url = videoType($url);
655 $out .= '<iframe width="308" height="204" src="' . esc_url($url) . '" frameborder="0" allowfullscreen=""></iframe>';
656 }
657 $out .= '</li>';
658 }
659 if (has_post_thumbnail()) {
660 $url = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
661 $out .= '<li>' . get_the_post_thumbnail(get_the_ID(), 'awada_blog_home_thumb', $img_class) . '</li>';
662 }
663 $out .= '</ul><!-- end slides -->
664 </div><!-- end post-slider -->';
665 } elseif (has_post_thumbnail()) {
666 $url = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()));
667 $out .= get_the_post_thumbnail(get_the_ID(), 'awada_blog_home_thumb', $img_class);
668 $out .= '<div class="magnifier">
669 <div class="buttons">
670 <a class="st" rel="bookmark" href="' . get_the_permalink() . '"><i class="fa fa-link"></i></a>
671 <a class="sf" data-gal="prettyPhoto[product-gallery]" href="' . esc_url($url) . '"><i class="fa fa-expand"></i></a>
672 </div><!-- end buttons -->
673 </div><!-- end magnifier -->';
674 }elseif(get_post_meta(get_the_ID(), 'awada_video_post_url', true) != "") {
675 $url = get_post_meta(get_the_ID(), 'awada_video_post_url', true);
676 $url = videoType($url);
677 $out .= '<iframe width="330" height="206" src="'.$url.'" frameborder="0" allowfullscreen=""></iframe>';
678 }
679 $out .= '</div><!-- end content_entry -->
680 <div class="blog-carousel-header">
681 <h3><a title="' . the_title_attribute('echo=0') . '" href="' . get_the_permalink() . '">' . get_the_title() . '</a></h3>
682 <div class="blog-carousel-meta">
683 <span><i class="fa fa-calendar"></i><a href="' . get_the_permalink() . '">' . esc_attr(get_the_date(get_option('date_format'), get_the_ID())) . '</a></span>
684 <span><i class="fa fa-comment"></i>';
685 if (comments_open()) {
686 $num_comments = get_comments_number();
687 if ($num_comments == 0) {
688 $comments = __('No Comments', 'awada');
689 } elseif ($num_comments > 1) {
690 $comments = $num_comments . __(' Comments', 'awada');
691 } else {
692 $comments = __('1 Comment', 'awada');
693 }
694 $out .= '<a href="' . get_comments_link() . '">' . $comments . '</a>';
695 } else {
696 $out .= __('Comments Off', 'awada');
697 }
698 $out .= '</span><span><i class="fa fa-user"></i> <a href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_attr(get_the_author()) . '</a></span>
699
700 </div><!-- end blog-carousel-meta -->
701 </div><!-- end blog-carousel-header -->
702 <div class="blog-carousel-desc">
703 ' . awada_excerpt(80) . '
704 </div><!-- end blog-carousel-desc -->
705 </div><!-- end blog-carousel -->
706 <div class="awada_blog_shadow"></div>
707 </div><!-- end col-lg-4 -->';
708 endwhile;
709 endif;
710
711 wp_reset_postdata();
712
713 wp_die($out);
714 }
715}
716?>