function hocwp_slider_html($args = array()) { if (!is_array($args)) { $position = $args; } else { $position = hocwp_get_value_by_key($args, 'position'); } $slider = hocwp_get_slider_by_position($position); if (hocwp_is_post($slider)) { $items = hocwp_get_post_meta('slider_items', $slider->ID); $order = hocwp_get_value_by_key($items, 'order'); if (!empty($order)) { $order = explode(',', $order); $items = hocwp_get_value_by_key($items, 'items'); $slider_class = 'hocwp-slider'; $thumbs = (bool) hocwp_get_value_by_key($args, 'thumbs', false); if ($thumbs) { hocwp_add_string_with_space_before($slider_class, 'thumbs-paging'); } hocwp_add_string_with_space_before($slider_class, hocwp_sanitize_html_class($position)); $custom_arrow = hocwp_get_value_by_key($args, 'custom_arrow'); if ($custom_arrow) { $slider_class = hocwp_add_more_class($slider_class, 'custom-arrow'); } $fit_width = hocwp_get_post_meta('fit_width', $slider->ID); $fit_width = hocwp_int_to_bool($fit_width); $height = hocwp_get_post_meta('height', $slider->ID); if (!hocwp_is_positive_number($height)) { $height = 350; } $atts = array('data-height="' . $height . '"'); if ($fit_width) { $atts[] = 'data-fit-width="1"'; } $atts = implode(' ', $atts); if (!empty($atts)) { $atts = ' ' . $atts; $atts = rtrim($atts); } echo '<div class="' . $slider_class . '">'; echo '<ul class="list-unstyled list-items slickslide list-inline"' . $atts . '>'; $list_paging = ''; $lazyload = hocwp_get_value_by_key($args, 'lazyload'); foreach ($order as $item_id) { $item = hocwp_get_value_by_key($items, $item_id); if (hocwp_array_has_value($item)) { $title = hocwp_get_value_by_key($item, 'title'); $link = hocwp_get_value_by_key($item, 'link'); $description = hocwp_get_value_by_key($item, 'description'); $image_url = hocwp_get_value_by_key($item, 'image_url'); $image_id = hocwp_get_value_by_key($item, 'image_id'); $image_url = hocwp_return_media_url($image_url, $image_id); $img = new HOCWP_HTML('img'); $img->set_image_src($image_url); $img->add_class('slider-image'); $li = new HOCWP_HTML('li'); $li->set_text($img); $li->add_class('slider-item'); if ($lazyload) { $li->add_class('lazyload'); $img->set_attribute('data-original', $image_url); $img->set_image_src(hocwp_get_image_url('transparent.gif')); } $list_paging .= $li->build(); if (!empty($link)) { $a = new HOCWP_HTML('a'); $a->set_href($link); $a->set_text($img); $li->set_text($a); } else { $li->set_text($img); } $li->output(); } } echo '</ul>'; if ($thumbs) { echo '<div class="thumbs-paging slick-thumbs">'; echo '<ul class="list-unstyled list-paging">'; echo $list_paging; echo '</ul>'; echo '</div>'; } echo '</div>'; } } }
function hocwp_shortcode_post_callback($atts = array(), $content = null) { $defaults = array('order' => 'desc', 'orderby' => 'date', 'by' => 'related', 'post_type' => 'post', 'title' => __('Related posts', 'hocwp-theme'), 'offset' => 0, 'column' => 4, 'number' => hocwp_get_posts_per_page(), 'border_color' => '', 'exclude_current' => true, 'display' => 'left', 'excerpt_length' => 0, 'style' => '', 'post' => '', 'posts' => '', 'thumbnail_size' => '180,110', 'interval' => ''); $attributes = shortcode_atts($defaults, $atts); $transient_name = 'hocwp_shortcode_post_%s'; $transient_name = hocwp_build_transient_name($transient_name, $attributes); if (false === ($html = get_transient($transient_name))) { $order = $attributes['order']; $orderby = $attributes['orderby']; $by = $attributes['by']; $post_type = hocwp_string_to_array(',', $attributes['post_type']); $post_type = array_map('trim', $post_type); $offset = $attributes['offset']; $column = $attributes['column']; if (!hocwp_is_positive_number($column)) { $column = 1; } $number = $attributes['number']; $posts_per_page = hocwp_get_first_divisible_of_divisor($number, $column); $exclude_current = (bool) $attributes['exclude_current']; $display = $attributes['display']; $display = trim($display); $excerpt_length = $attributes['excerpt_length']; $post = $attributes['post']; $post = hocwp_find_post($post); $posts = $attributes['posts']; $posts = hocwp_string_to_array(',', $posts); $thumbnail_size = $attributes['thumbnail_size']; $thumbnail_size = hocwp_sanitize_size($thumbnail_size); $interval = $attributes['interval']; if (hocwp_is_post($post)) { $display = 'full'; } $class = 'hocwp-shortcode-post'; hocwp_add_string_with_space_before($class, $order); hocwp_add_string_with_space_before($class, $by); hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($display)); if ('100%' == $display) { $class = hocwp_add_more_class($class, 'full-width'); } hocwp_add_string_with_space_before($class, implode(' ', $post_type)); $query = null; if (!hocwp_is_post($post)) { $args = array('post_type' => $post_type, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby); if (!empty($interval)) { hocwp_query_sanitize_date_query_args($interval, $args); } if ($exclude_current && is_singular()) { $post_id = get_the_ID(); $args['post__not_in'] = array($post_id); } if (hocwp_array_has_value($posts)) { $args['post__in'] = $posts; } $query = hocwp_query_by($by, $args); } else { if (!hocwp_is_positive_number($excerpt_length)) { $excerpt_length = 200; } } if (hocwp_is_post($post) || hocwp_object_valid($query) && $query->have_posts()) { $html = hocwp_shortcode_before($class, $attributes); $width = $thumbnail_size[0]; if (hocwp_is_post($post)) { global $post; setup_postdata($post); ob_start(); ?> <div class="one-post"> <div <?php post_class('', $post); ?> > <?php if ($width > 0) { hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1], 'post_id' => $post->ID)); } hocwp_post_title_link(array('title' => $post->post_title, 'permalink' => get_permalink($post))); if (hocwp_is_positive_number($excerpt_length)) { hocwp_entry_summary($excerpt_length); } ?> </div> </div> <?php $html .= ob_get_clean(); wp_reset_postdata(); } else { $html .= '<div class="in-loop row-small">'; $loop = apply_filters('hocwp_shortcode_post_pre_loop', '', $query, $attributes); if (empty($loop)) { $count = 1; $style = ''; if ('left' != $display && 'right' != $display) { $style = 'width:' . hocwp_column_width_percentage($column); } while ($query->have_posts()) { $query->the_post(); $html_loop = apply_filters('hocwp_shortcode_post_loop', '', $attributes); if (empty($html_loop)) { $item_class = 'item'; if (hocwp_is_last_item($count, $column)) { hocwp_add_string_with_space_before($item_class, 'last-item'); } elseif (hocwp_is_first_item($count, $column)) { hocwp_add_string_with_space_before($item_class, 'first-item'); } ob_start(); ?> <div class="<?php echo $item_class; ?> " style="<?php echo $style; ?> "> <div <?php post_class(); ?> > <?php if ($width > 0) { hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1])); } hocwp_post_title_link(); if (hocwp_is_positive_number($excerpt_length)) { hocwp_entry_summary($excerpt_length); } ?> </div> </div> <?php $html_loop = ob_get_clean(); } $loop .= $html_loop; $count++; } wp_reset_postdata(); } $html .= $loop; $html .= '</div>'; } $html .= hocwp_shortcode_after(); } else { $html = ''; } if (!empty($html)) { set_transient($transient_name, $html, WEEK_IN_SECONDS); } } return apply_filters('hocwp_shortcode_post', $html, $attributes, $content); }
function hocwp_show_ads($args = array()) { $ads = $args; $position = ''; if (!is_object($args)) { if (!is_array($args)) { $args = array('position' => $args); } $position = hocwp_get_value_by_key($args, 'position'); if (!empty($position)) { $random = (bool) hocwp_get_value_by_key($args, 'random'); $current_datetime = date(hocwp_get_date_format()); $current_datetime = strtotime($current_datetime); $query_args = array('post_type' => 'hocwp_ads', 'posts_per_page' => 1, 'meta_query' => array('relation' => 'AND', array('relation' => 'OR', array('key' => 'expire', 'compare' => 'NOT EXISTS'), array('key' => 'expire', 'value' => '', 'compare' => '='), array('key' => 'expire', 'value' => 0, 'type' => 'numeric'), array('key' => 'expire', 'value' => $current_datetime, 'type' => 'numeric', 'compare' => '>=')), array('key' => 'active', 'value' => 1, 'type' => 'numeric'))); if ($random) { $query_args['orderby'] = 'rand'; } $ads = hocwp_get_post_by_meta('position', $position, $query_args); if ($ads->have_posts()) { $posts = $ads->posts; $ads = array_shift($posts); } } } if (hocwp_is_post($ads) && 'hocwp_ads' == $ads->post_type) { $code = hocwp_get_post_meta('code', $ads->ID); if (empty($code)) { $image = hocwp_get_post_meta('image', $ads->ID); $image = hocwp_sanitize_media_value($image); $image = $image['url']; if (!empty($image)) { $img = new HOCWP_HTML('img'); $img->set_image_src($image); $url = hocwp_get_post_meta('url', $ads->ID); if (!empty($url)) { $a = new HOCWP_HTML('a'); $a->set_href($url); $a->set_text($img); $code = $a->build(); } else { $code = $img->build(); } } } if (!empty($code)) { $class = hocwp_get_value_by_key($args, 'class'); hocwp_add_string_with_space_before($class, 'hocwp-ads text-center ads'); if (!empty($position)) { hocwp_add_string_with_space_before($class, 'position-' . $position); $position = hocwp_sanitize_html_class($position); $class = hocwp_add_more_class($class, $position); } hocwp_add_string_with_space_before($class, $ads->post_name); $div = new HOCWP_HTML('div'); $div->set_class($class); $div->set_text($code); $html = $div->build(); $html = apply_filters('hocwp_ads_html', $html, $ads_or_args = $args); echo $html; } } }