'; } } add_action( 'wp_head', 'ansupa_pingback_header' ); /** * Get an array of post id and title. * */ function ansupa_get_post_choices() { $choices = array( '' => esc_html__( '--Select--', 'ansupa' ) ); $args = array( 'numberposts' => -1, ); $posts = get_posts( $args ); foreach ( $posts as $post ) { $id = $post->ID; $title = $post->post_title; $choices[ $id ] = $title; } return $choices; wp_reset_postdata(); } function ansupa_get_page_choices() { $pages = get_pages(); $choices = array(); $choices[0] = esc_html__( '--Select--', 'ansupa' ); foreach ( $pages as $page ) { $choices[ $page->ID ] = $page->post_title; } return $choices; } /** * Get an array of cat id and title. * */ function ansupa_get_post_cat_choices() { $choices = array( '' => esc_html__( '--Select--', 'ansupa' ) ); $cats = get_categories(); foreach ( $cats as $cat ) { $id = $cat->term_id; $title = $cat->name; $choices[ $id ] = $title; } return $choices; } /** * Get an list of category sluf. * */ function ansupa_get_category_slug_list($post_id) { $cat_list = wp_get_post_categories($post_id); $cat_slug = ""; foreach($cat_list as $cat_id){ $cat = get_category($cat_id); $cat_slug = $cat_slug . "".$cat->slug . " "; } return $cat_slug; } /** * Checks to see if we're on the homepage or not. */ function ansupa_is_frontpage() { return ( is_front_page() && ! is_home() ); } /** * Checks to see if Static Front Page is set to "Your latest posts". */ function ansupa_is_latest_posts() { return ( is_front_page() && is_home() ); } /** * Checks to see if Static Front Page is set to "Posts page". */ function ansupa_is_frontpage_blog() { return ( is_home() && ! is_front_page() ); } /** * Checks to see if the current page displays any kind of post listing. */ function ansupa_is_page_displays_posts() { return ( ansupa_is_frontpage_blog() || is_search() || is_archive() || ansupa_is_latest_posts() ); } /** * Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class, * which should be used in theme templates. * * @since 1.0.0 * @access public * @param array $args Arguments to pass to Breadcrumb_Trail. * @return void */ function ansupa_breadcrumb( $args = array() ) { $breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $args ); if ( ! is_object( $breadcrumb ) ) $breadcrumb = new Breadcrumb_Trail( $args ); return $breadcrumb->trail(); } /** * Pagination in archive/blog/search pages. */ function ansupa_posts_pagination() { $archive_pagination = get_theme_mod( 'ansupa_archive_pagination_type', 'numeric' ); if ( 'disable' === $archive_pagination ) { return; } if ( 'numeric' === $archive_pagination ) { the_posts_pagination( array( 'prev_text' => ansupa_get_svg( array( 'icon' => 'left-arrow' ) ), 'next_text' => ansupa_get_svg( array( 'icon' => 'left-arrow' ) ), ) ); } elseif ( 'older_newer' === $archive_pagination ) { the_posts_navigation( array( 'prev_text' => ansupa_get_svg( array( 'icon' => 'left' ) ) . ''. esc_html__( 'Older', 'ansupa' ) .'', 'next_text' => ''. esc_html__( 'Newer', 'ansupa' ) .'' . ansupa_get_svg( array( 'icon' => 'right' ) ), ) ); } } function ansupa_get_svg_by_url( $url = false ) { if ( ! $url ) { return false; } $social_icons = ansupa_social_links_icons(); foreach ( $social_icons as $attr => $value ) { if ( false !== strpos( $url, $attr ) ) { return ansupa_get_svg( array( 'icon' => esc_attr( $value ) ) ); } } } if ( ! function_exists( 'ansupa_the_excerpt' ) ) : /** * Generate excerpt. * * @since 1.0.0 * * @param int $length Excerpt length in words. * @param WP_Post $post_obj WP_Post instance (Optional). * @return string Excerpt. */ function ansupa_the_excerpt( $length = 0, $post_obj = null ) { global $post; if ( is_null( $post_obj ) ) { $post_obj = $post; } $length = absint( $length ); if ( 0 === $length ) { return; } $source_content = $post_obj->post_content; if ( ! empty( $post_obj->post_excerpt ) ) { $source_content = $post_obj->post_excerpt; } $source_content = preg_replace( '`\[[^\]]*\]`', '', $source_content ); $trimmed_content = wp_trim_words( $source_content, $length, '…' ); return $trimmed_content; } endif; function ansupa_get_section_content( $section_name, $content_type, $content_count ){ $content = array(); if ( in_array( $content_type, array( 'post', 'page' ) ) ) { $content_id = array(); if ( 'post' === $content_type ) { for ( $i=1; $i <= $content_count; $i++ ) { $content_id[] = get_theme_mod( "ansupa_{$section_name}_{$content_type}_" . $i ); } }else { for ( $i=1; $i <= $content_count; $i++ ) { $content_id[] = get_theme_mod( "ansupa_{$section_name}_{$content_type}_" . $i ); } } $args = array( 'post_type' => $content_type, 'post__in' => (array)$content_id, 'orderby' => 'post__in', 'posts_per_page' => absint( $content_count ), 'ignore_sticky_posts' => true, ); } else { $cat_content_id = get_theme_mod( "ansupa_{$section_name}_{$content_type}" ); $args = array( 'cat' => $cat_content_id, 'posts_per_page' => absint( $content_count ), ); } $query = new WP_Query( $args ); if ( $query->have_posts() ) { $i = 0; while ( $query->have_posts() ) { $query->the_post(); $content[$i]['id'] = get_the_id(); $content[$i]['title'] = get_the_title(); $content[$i]['url'] = get_the_permalink(); $content[$i]['content'] = get_the_content(); $i++; } wp_reset_postdata(); } return $content; } // Add auto p to the palces where get_the_excerpt is being called. add_filter( 'get_the_excerpt', 'wpautop' ); if ( ! function_exists( 'ansupa_category_title' ) ) : function ansupa_category_title( $title ) { if ( is_category() ) { $title = single_cat_title( '', false ); } return $title; } add_filter( 'get_the_archive_title', 'ansupa_category_title' ); endif; function ansupa_category_choices() { $tax_args = array( 'hierarchical' => 0, 'taxonomy' => 'category', ); $taxonomies = get_categories( $tax_args ); $choices = array(); $choices[0] = esc_html__( '--Select--', 'ansupa' ); foreach ( $taxonomies as $tax ) { $choices[ $tax->term_id ] = $tax->name; } return $choices; } function ansupa_return_social_icon( $social_link ) { // Get supported social icons. $social_icons = ansupa_social_links_icons(); // Check in the URL for the url in the array. foreach ( $social_icons as $attr => $value ) { if ( false !== strpos( $social_link, $attr ) ) { return ansupa_get_svg( array( 'icon' => esc_attr( $value ) ) ); } } } if ( ! function_exists( 'ansupa_ajax_enqueuer' ) ) : /** * ajax enquue * */ function ansupa_ajax_enqueuer() { wp_register_script( "ansupa-ajax", get_template_directory_uri() . '/assets/js/blog-ajax.js', array( 'jquery' ), '', true ); wp_localize_script( 'ansupa-ajax', 'ansupa', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( 'ansupa-ajax' ); } endif; add_action( 'wp_enqueue_scripts', 'ansupa_ajax_enqueuer' ); if ( ! function_exists( 'ansupa_latest_posts_ajax_handler' ) ) : /** * ajax handler * */ function ansupa_latest_posts_ajax_handler(){ $blog = get_theme_mod( 'ansupa_blog_posts', 'cat' ); $blog_num = get_theme_mod( 'ansupa_blog_posts_count', 4 ) ; $page = isset( $_POST['LBpageNumber'] ) ? absint( wp_unslash( $_POST['LBpageNumber'] ) ) : 1; header("Content-Type: text/html"); $blog_content_type = get_theme_mod( 'ansupa_blog_posts', 'cat' ); $blog_posts_excerpt = get_theme_mod( 'ansupa_blog_posts_excerpt', 20 ); // Query if the content type is either post or page. if ( in_array( $blog, array( 'post', 'page' ) ) ) { $content_id = array(); if ( 'post' === $blog ) { for ( $i=1; $i <= $blog_num; $i++ ) { $content_id[] = get_theme_mod( "ansupa_blog_posts{$blog}_" . $i ); } }else { for ( $i=1; $i <= $blog_num; $i++ ) { $content_id[] = get_theme_mod( "ansupa_blog_posts{$blog}_" . $i ); } } $args = array( 'post_type' => $blog, 'post__in' => (array)$content_id, 'orderby' => 'post__in', 'posts_per_page' => absint( $blog_num ), 'ignore_sticky_posts' => true, 'orderby' => 'post__in', 'post_status' => array( 'publish' ), 'paged' => $page, ); } else { $cat_content_id = get_theme_mod( 'ansupa_blog_posts_cat' ); $args = array( 'post_type' => 'post', 'cat' => $cat_content_id, 'posts_per_page' => absint( $blog_num ), 'ignore_sticky_posts' => true, 'post_status' => array( 'publish' ), 'paged' => $page, ); } $latest_posts = new WP_Query( $args ); if ( $latest_posts -> have_posts() ) : while ( $latest_posts -> have_posts() ) : $latest_posts -> the_post(); $banner_thumbnail = !empty( get_the_post_thumbnail_url( ) ) ? get_the_post_thumbnail_url( get_the_id(), 'medium-large' ) : get_template_directory_uri(). '/assets/img/no-featured-image.jpg'; ?>