$post_type, 'posts_per_page' => absint($number_of_posts), 'paged' => $paged, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC' ); if (absint($category_id) > 0) { $ins_args['tax_query'] = array( array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => absint($category_id) ) ); } $all_posts = new WP_Query($ins_args); return $all_posts; } endif; /** * Returns all categories. * * @since StoreCommerce 1.0.0 */ if (!function_exists('storecommerce_get_terms')): function storecommerce_get_terms( $taxonomy='category', $category_id = 0, $default='' ){ $taxonomy = !empty($taxonomy) ? $taxonomy : 'category'; if ( $category_id > 0 ) { $term = get_term_by('id', absint($category_id), $taxonomy ); if($term) return esc_html($term->name); } else { $terms = get_terms(array( 'taxonomy' => $taxonomy, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, )); if (isset($terms) && !empty($terms)) { foreach ($terms as $term) { if( $default != 'first' ){ $array['0'] = __('Select Category', 'storecommerce'); } $array[$term->term_id] = esc_html($term->name); } return $array; } } } endif; /** * Returns all categories. * * @since StoreCommerce 1.0.0 */ if (!function_exists('storecommerce_get_terms_link')): function storecommerce_get_terms_link( $category_id = 0 ){ if (absint($category_id) > 0) { return get_term_link(absint($category_id), 'category'); } else { return get_post_type_archive_link('post'); } } endif; /** * Returns word count of the sentences. * * @since StoreCommerce 1.0.0 */ if (!function_exists('storecommerce_get_excerpt')): function storecommerce_get_excerpt($length = 25, $storecommerce_content = null, $post_id = 1) { $length = absint($length); $source_content = preg_replace('`\[[^\]]*\]`', '', $storecommerce_content); $trimmed_content = wp_trim_words($source_content, $length, '...'); return $trimmed_content; } endif; /** * Returns word count of the sentences. * * @since StoreCommerce 1.0.0 */ if (!function_exists('storecommerce_excerpt_ellisis')): function storecommerce_excerpt_ellisis($length = 25, $storecommerce_content = null, $post_id = 1) { if ( ! is_admin() ) { global $post; //$more = '…. Continue reading.'; //$more = ''. __("Read More", "storecommerce") .'"'; $more = sprintf('%2s',get_permalink($post->ID), __("Read More", "storecommerce")); return $more; } } endif; add_filter('excerpt_more', 'storecommerce_excerpt_ellisis'); /** * Returns no image url. * * @since StoreCommerce 1.0.0 */ if(!function_exists('storecommerce_no_image_url')): function storecommerce_no_image_url(){ $url = get_template_directory_uri().'/assets/images/no-image.png'; return $url; } endif; /** * Returns no image url. * * @since StoreCommerce 1.0.0 */ if(!function_exists('storecommerce_post_format')): function storecommerce_post_format($post_id){ $post_format = get_post_format($post_id); switch ($post_format) { case "image": echo "
"; break; case "video": echo "
"; break; case "gallery": echo "
"; break; default: echo ""; } } endif; /** * Outputs the tab posts * * @since 1.0.0 * * @param array $args Post Arguments. */ if (!function_exists('storecommerce_render_posts')): function storecommerce_render_posts( $type, $show_excerpt, $excerpt_length, $number_of_posts, $category = '0' ){ $args = array(); switch ($type) { case 'popular': $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => absint($number_of_posts), 'orderby' => 'comment_count', 'ignore_sticky_posts' => true ); break; case 'recent': $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => absint($number_of_posts), 'orderby' => 'date', 'ignore_sticky_posts' => true ); break; case 'categorised': $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => absint($number_of_posts), 'ignore_sticky_posts' => true ); $category = isset($category) ? $category : '0'; if (absint($category) > 0) { $args['cat'] = absint($category); } break; default: break; } if( !empty($args) && is_array($args) ){ $all_posts = new WP_Query($args); if($all_posts->have_posts()): echo '