max_num_pages; $localize['pagination'] = $blog_pagination; $localize['infinite_scroll_event'] = $blog_infinite_scroll_event; $localize['no_more_post_message'] = apply_filters( 'astra_blog_no_more_post_text', __( 'No more posts to show.', 'astra-addon' ) ); $localize['grid_layout'] = $grid_layout; $localize['site_url'] = get_site_url(); $localize['blogArchiveTitleLayout'] = astra_get_option( 'ast-dynamic-archive-post-layout' ); $localize['blogArchiveTitleOn'] = astra_get_option( 'ast-dynamic-archive-post-banner-on-blog' ); $localize['show_comments'] = __( 'Show Comments', 'astra-addon' ); // If woocommerce page template. if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) { $localize['masonryEnabled'] = false; } else { $localize['masonryEnabled'] = $blog_masonry; $localize['blogMasonryBreakPoint'] = absint( apply_filters( 'astra_blog_masonry_break_point', 0 ) ); } return $localize; } /** * Astra Blog Pagination * * @since 1.0 * @param html $output Pagination markup. * @return html */ public function astra_blog_pagination( $output ) { global $wp_query; $pagination = astra_get_option( 'blog-pagination' ); $infinite_event = astra_get_option( 'blog-infinite-scroll-event' ); $load_more_text = astra_get_option( 'blog-load-more-text' ); if ( '' === $load_more_text ) { $load_more_text = __( 'Load More', 'astra-addon' ); } if ( 'infinite' == $pagination ) { ob_start(); ?>
max_num_pages > 1 ) { ?>
%2$s %3$s %4$s'; $time_string = sprintf( $time_string, ( 'updated' === $date_type ) ? esc_attr( get_the_modified_date( 'c' ) ) : esc_attr( get_the_date( 'c' ) ), ( 'updated' === $date_type ) ? esc_attr( get_the_modified_date( 'M' ) ) : esc_html( get_the_date( 'M' ) ), ( 'updated' === $date_type ) ? esc_attr( get_the_modified_date( 'j' ) ) : esc_html( get_the_date( 'j' ) ), ( 'updated' === $date_type ) ? esc_attr( get_the_modified_date( 'Y' ) ) : esc_html( get_the_date( 'Y' ) ) ); /** * Filters the Date Box time format. * * @since 1.5.0 * * @param string posted date format for the posts. */ $posted_on = apply_filters( 'astra_date_box_time_format', sprintf( esc_html( '%s' ), $time_string ) ); ob_start(); ?>
array( 'class' => array(), 'datetime' => array(), ), 'span' => array( 'class' => array() ), ) ); ?>
1 && $first_post_full_width && ! $blog_masonry && 0 == $wp_query->current_post && 1 == $paged ) { // Feature Post. if ( 3 == $blog_grid ) { $classes[] = Astra_Addon_Builder_Helper::apply_flex_based_css() ? 'ast-width-md-66' : 'ast-col-md-8'; } elseif ( 4 == $blog_grid ) { $classes[] = Astra_Addon_Builder_Helper::apply_flex_based_css() ? 'ast-width-50' : 'ast-col-md-6'; } else { $classes[] = Astra_Addon_Builder_Helper::apply_flex_based_css() ? 'ast-grid-common-col' : 'ast-col-md-12'; } $classes[] = 'ast-featured-post'; } else { $classes[] = Astra_Addon_Builder_Helper::apply_flex_based_css() ? 'ast-width-md-' . ( 12 / $blog_grid ) : 'ast-col-md-' . ( 12 / $blog_grid ); } } else { if ( $blog_grid_layout > 1 && $first_post_full_width && ! $blog_masonry && 0 == $wp_query->current_post && 1 == $paged ) { // Feature Post. $classes[] = 'ast-col-md-12'; $classes[] = 'ast-featured-post'; } else { $classes[] = Astra_Addon_Builder_Helper::apply_flex_based_css() ? 'ast-width-md-' . ( 12 / $blog_grid_layout ) : 'ast-col-md-' . ( 12 / $blog_grid_layout ); } } if ( true === astra_addon_builder_helper()->is_header_footer_builder_active ) { $classes[] = 'ast-archive-post'; } if ( $blog_space_bet_posts ) { $classes[] = 'ast-separate-posts'; } if ( astra_addon_check_reveal_effect_condition( 'blog' ) || ( astra_addon_check_reveal_effect_condition( 'cpt' ) && ( is_archive() || is_tax() ) ) ) { $classes[] = 'ast-fade-up'; } } elseif ( is_singular() ) { $blog_layout = astra_addon_get_blog_layout(); $remove_featured_padding = astra_get_option( 'single-featured-image-padding' ); if ( 'blog-layout-1' == $blog_layout && $remove_featured_padding ) { $classes[] = 'remove-featured-img-padding'; } } return $classes; } /** * Add Body Classes * * @param array $classes Body Class Array. * @return array */ public function astra_ext_blog_pro_body_classes( $classes ) { if ( is_archive() || is_home() || is_search() ) { global $wp_query; $blog_layout = astra_addon_get_blog_layout(); $blog_masonry = astra_get_option( 'blog-masonry' ); $blog_grid = astra_addon_get_blog_grid_columns( 'desktop' ); $blog_grid_layout = astra_get_option( 'blog-grid-layout' ); $blog_pagination = astra_get_option( 'blog-pagination' ); // Masonry layout for blog. if ( $blog_masonry && $wp_query->posts ) { $classes[] = 'blog-masonry'; } // Blog layout. if ( 'blog-layout-1' == $blog_layout || 'blog-layout-4' == $blog_layout || 'blog-layout-5' == $blog_layout || 'blog-layout-6' == $blog_layout ) { $classes[] = 'ast-blog-grid-' . esc_attr( $blog_grid ); } else { $classes[] = 'ast-blog-grid-' . esc_attr( $blog_grid_layout ); } // Blog layout. $classes[] = 'ast-' . esc_attr( $blog_layout ); if ( 'infinite' === $blog_pagination ) { // Pagination type. $classes[] = 'ast-blog-pagination-type-infinite'; } if ( 'number' === $blog_pagination ) { $blog_pagination_style = astra_get_option( 'blog-pagination-style' ); $classes[] = 'ast-pagination-' . esc_attr( $blog_pagination_style ); } } return $classes; } /** * Add style. * * @since 1.0 * * @return void. */ public function add_styles() { $author_info = astra_get_option( 'ast-author-info' ); $enable_related_posts = astra_get_option( 'enable-related-posts' ); $blog_layout = astra_addon_get_blog_layout(); $blog_layout_path = ''; /*** Start Path Logic */ /* Define Variables */ $uri = ASTRA_ADDON_EXT_BLOG_PRO_URI . 'assets/css/'; $path = ASTRA_ADDON_EXT_BLOG_PRO_DIR . 'assets/css/'; $rtl = ''; if ( is_rtl() ) { $rtl = '-rtl'; } /* Directory and Extension */ $file_prefix = $rtl . '.min'; $dir_name = 'minified'; if ( SCRIPT_DEBUG ) { $file_prefix = $rtl; $dir_name = 'unminified'; } $css_uri = $uri . $dir_name . '/'; $css_dir = $path . $dir_name . '/'; if ( defined( 'ASTRA_THEME_HTTP2' ) && ASTRA_THEME_HTTP2 ) { $gen_path = $css_uri; } else { $gen_path = $css_dir; } /*** End Path Logic */ /* Add style.css */ Astra_Minify::add_css( $gen_path . 'style' . $file_prefix . '.css' ); if ( $author_info ) { Astra_Minify::add_css( $gen_path . 'post-author' . $file_prefix . '.css' ); } if ( $enable_related_posts ) { Astra_Minify::add_css( $gen_path . 'related-posts' . $file_prefix . '.css' ); } /* Blog Layouts */ if ( true === Astra_Addon_Builder_Helper::apply_flex_based_css() && ( 'blog-layout-2' == $blog_layout || 'blog-layout-3' == $blog_layout ) ) { $blog_layout_path = $blog_layout . '-flex'; } else { $blog_layout_path = $blog_layout; } if ( 'blog-layout-1' == $blog_layout || 'blog-layout-2' == $blog_layout || 'blog-layout-3' == $blog_layout ) { Astra_Minify::add_css( $gen_path . $blog_layout_path . $file_prefix . '.css' ); } } /** * Add scripts. * * @since 1.0 * * @return void. */ public function add_scripts() { /*** Start Path Logic */ /* Define Variables */ $uri = ASTRA_ADDON_EXT_BLOG_PRO_URI . 'assets/js/'; $path = ASTRA_ADDON_EXT_BLOG_PRO_DIR . 'assets/js/'; /* Directory and Extension */ $file_prefix = '.min'; $dir_name = 'minified'; if ( SCRIPT_DEBUG ) { $file_prefix = ''; $dir_name = 'unminified'; } $js_uri = $uri . $dir_name . '/'; $js_dir = $path . $dir_name . '/'; if ( defined( 'ASTRA_THEME_HTTP2' ) && ASTRA_THEME_HTTP2 ) { $gen_path = $js_uri; } else { $gen_path = $js_dir; } /*** End Path Logic */ $blog_layout = astra_addon_get_blog_layout(); $blog_grid = astra_addon_get_blog_grid_columns( 'desktop' ); $blog_grid_layout = astra_get_option( 'blog-grid-layout' ); $astra_blog_masonry = astra_get_option( 'blog-masonry' ); $blog_filter = astra_get_option( 'blog-filter' ); if ( ( ( 'blog-layout-1' == $blog_layout && 1 != $blog_grid ) || ( 'blog-layout-1' != $blog_layout && 1 != $blog_grid_layout ) ) || ( 'blog-layout-4' == $blog_layout && 1 != $blog_grid ) || ( 'blog-layout-6' == $blog_layout && 1 != $blog_grid ) ) { // Enqueue scripts. if ( $astra_blog_masonry ) { Astra_Minify::add_dependent_js( 'jquery' ); Astra_Minify::add_dependent_js( 'jquery-masonry' ); Astra_Minify::add_js( $gen_path . 'ast-ext-blog-pro' . $file_prefix . '.js' ); } } if ( $blog_filter ) { Astra_Minify::add_js( $gen_path . 'filter' . $file_prefix . '.js' ); } } /** * Frontend scripts. * * @since 1.0 * * @return void. */ public function enqueue_frontend_scripts() { $blog_pagination = astra_get_option( 'blog-pagination' ); /* Directory and Extension */ $file_prefix = '.min'; $dir_name = 'minified'; if ( SCRIPT_DEBUG ) { $file_prefix = ''; $dir_name = 'unminified'; } $js_gen_path = ASTRA_ADDON_EXT_BLOG_PRO_URI . 'assets/js/' . $dir_name . '/'; $css_gen_path = ASTRA_ADDON_EXT_BLOG_PRO_URI . 'assets/css/' . $dir_name . '/'; if ( astra_get_option( 'ast-auto-prev-post' ) && is_singular() ) { if ( SCRIPT_DEBUG ) { wp_enqueue_script( 'astra-scrollspy', $js_gen_path . 'scrollspy' . $file_prefix . '.js', array( 'jquery' ), ASTRA_EXT_VER, true ); wp_enqueue_script( 'astra-history', $js_gen_path . 'jquery-history' . $file_prefix . '.js', array( 'jquery' ), ASTRA_EXT_VER, true ); wp_enqueue_script( 'astra-single-infinite', $js_gen_path . 'single-infinite' . $file_prefix . '.js', array( 'astra-scrollspy' ), ASTRA_EXT_VER, true ); } else { wp_enqueue_script( 'astra-single-infinite', $js_gen_path . 'single-autopost-infinite.min.js', array( 'jquery' ), ASTRA_EXT_VER, true ); } } // Load infinite js only if option is used. if ( ( is_home() || is_archive() || is_search() ) && 'infinite' === $blog_pagination ) { wp_enqueue_script( 'astra-pagination-infinite', $js_gen_path . 'pagination-infinite' . $file_prefix . '.js', array( 'jquery', 'astra-addon-js' ), ASTRA_EXT_VER, true ); } } /** * Calculate reading time. * * @since 1.0 * * @param int $post_id Post content. * @return int read time. */ public function calculate_reading_time( $post_id ) { $post_content = get_post_field( 'post_content', $post_id ); $stripped_content = strip_shortcodes( $post_content ); $strip_tags_content = wp_strip_all_tags( $stripped_content ); $word_count = count( preg_split( '/\s+/', $strip_tags_content ) ); $reading_time = ceil( $word_count / 220 ); return $reading_time; } /** * Reading Time Meta. * * @since 1.3.3 Updated post reading time strings. * @since 1.0 * * @param string $content Post content. * @param string $loop_count Post meta loop count. * @param string $separator Separator text. * @return string content */ public function reading_time_content( $content = '', $loop_count = '', $separator = '' ) { $read_time = (int) $this->calculate_reading_time( get_the_ID() ); $singular_min_reading_text = apply_filters( 'astra_post_minute_of_reading_text', __( 'minute of reading', 'astra-addon' ) ); $plural_mins_reading_text = apply_filters( 'astra_post_minutes_of_reading_text', __( 'minutes of reading', 'astra-addon' ) ); $content .= ( 1 != $loop_count && '' != $content ) ? ' ' . $separator . ' ' : ''; /* translators: %1$s: $read_time the time to read the article, %2%s: $singular_min_reading_text the singular minute reading time text, %3%s: $plural_mins_reading_text the plural minutes reading time text */ $content .= '' . sprintf( _n( '%1$s %2$s', '%1$s %3$s', $read_time, 'astra-addon' ), $read_time, $singular_min_reading_text, $plural_mins_reading_text ) . ''; // phpcs:ignore WordPress.WP.I18n.MismatchedPlaceholders return $content; } /** * Init action. * * @return void */ public function init_action() { $this->single_post_add_endpoint(); if ( 'excerpt' === astra_get_option( 'blog-post-content' ) ) { // Excerpt Filter. add_filter( 'excerpt_length', array( $this, 'custom_excerpt_length' ) ); add_filter( 'astra_post_read_more', array( $this, 'read_more_text' ) ); add_filter( 'astra_post_read_more_class', array( $this, 'read_more_class' ) ); } } /** * Single post rewrite endpoint. * * @return void */ public function single_post_add_endpoint() { if ( astra_get_option( 'ast-auto-prev-post' ) || is_customize_preview() ) { add_rewrite_endpoint( 'partial-prev', EP_PERMALINK ); add_action( 'template_redirect', array( $this, 'single_post_template_redirect' ) ); add_action( 'astra_before_content_partial_loop', array( $this, 'auto_prev_post_wp_bakery_compatibility' ) ); } } /** * Added shortcode rendering compatibility for WP Bakery plugin. * * WP Bakery plugin shortcodes were not rendering when auto prev post option was enable. * * @return void */ public function auto_prev_post_wp_bakery_compatibility() { // Make sure all vc shortcodes are loaded (needed for ajax previous post pagination). if ( is_callable( 'WPBMap::addAllMappedShortcodes' ) ) { WPBMap::addAllMappedShortcodes(); } } /** * Single post template redirect. */ public function single_post_template_redirect() { global $wp_query; // if this is not a request for partial or a singular object then bail. if ( ( isset( $wp_query->query_vars['partial-prev'] ) || isset( $_GET['partial-prev'] ) ) && is_singular() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended // include custom template. include ASTRA_ADDON_EXT_BLOG_PRO_DIR . '/template/content-partial.php'; exit; } } /** * Excerpt count. * * @param int $length default count of words. * @return int count of words */ public function custom_excerpt_length( $length ) { $excerpt_length = astra_get_option( 'blog-excerpt-count' ); if ( '' != $excerpt_length ) { $length = $excerpt_length; } return $length; } /** * Read more text. * * @param string $text default read more text. * @return string read more text */ public function read_more_text( $text ) { $read_more = astra_get_option( 'blog-read-more-text' ); if ( '' != $read_more ) { $text = $read_more; } return $text; } /** * Read more class. * * @param array $class default classes. * @return array classes */ public function read_more_class( $class ) { $read_more_button = astra_get_option( 'blog-read-more-as-button' ); if ( $read_more_button ) { $class[] = 'ast-button'; } return $class; } /** * Social sharing. * * @since 4.1.0 */ public function astra_social_sharing() { $social_sharing_position = astra_get_option( 'single-post-social-sharing-icon-position' ); $is_social_sharing_enabled = astra_get_option( 'single-post-social-sharing-icon-enable' ); if ( $is_social_sharing_enabled ) { if ( is_single() ) { if ( 'below-post-title' === $social_sharing_position ) { add_action( 'astra_single_post_banner_after', array( $this, 'astra_render_social_sharing' ) ); } else { add_action( 'astra_entry_bottom', array( $this, 'astra_render_social_sharing' ) ); } } } } /** * Enqueue google fonts. * * @return void */ public function add_fonts() { // Single post social sharing - Label font. $label_font_family = astra_get_option( 'single-post-social-sharing-icon-label-font-family' ); $label_font_weight = astra_get_option( 'single-post-social-sharing-icon-label-font-weight' ); Astra_Fonts::add_font( $label_font_family, $label_font_weight ); // Single post social sharing - Label font. $heading_font_family = astra_get_option( 'single-post-social-sharing-heading-font-family' ); $heading_font_weight = astra_get_option( 'single-post-social-sharing-heading-font-weight' ); Astra_Fonts::add_font( $heading_font_family, $heading_font_weight ); } /** * Render Author Box sharing. * * @since 4.6.0 * @return mixed HTML markup */ public function astra_render_author_box_sharing() { $is_author_box_enabled = astra_get_option( 'ast-author-info' ); $social_sharing_enabled = astra_get_option( 'author-box-socials' ); if ( ! is_single() || ! $is_author_box_enabled || ! $social_sharing_enabled ) { return; } $prefix = 'author-box'; $title = get_the_title(); $show_label = false; $items = astra_get_option( 'author-box-social-icon-list' ); $items = isset( $items['items'] ) ? $items['items'] : array(); $post_categories = wp_strip_all_tags( get_the_category_list( ',' ) ); $post_title = $title; $post_link = urlencode( get_the_permalink() ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode $email_title = str_replace( '&', '%26', $title ); $enable_heading = astra_get_option( 'single-post-social-sharing-heading-enable' ); $heading_text = astra_get_option( 'single-post-social-sharing-heading-text' ); $heading_position = astra_get_option( 'single-post-social-sharing-heading-position' ); $show_label = $show_label; $show_label_class = $show_label ? 'social-show-label-true' : 'social-show-label-false'; $color_type = astra_get_option( 'single-post-social-sharing-icon-color-type' ); $label_position = astra_get_option( 'single-post-social-sharing-icon-label-position' ); $social_icon_condition = array( 'facebook', 'pinterest', 'linkedin', 'reddit', 'whatsapp', 'sms', 'telegram' ); $markup = '
'; if ( is_array( $items ) && ! empty( $items ) ) { foreach ( $items as $item ) { if ( $item['enabled'] ) { $link = $item['url']; switch ( $item['id'] ) { case 'phone': $link = 'tel:' . $item['url']; break; case 'email': $link = 'mailto:' . $item['url']; break; case 'whatsapp': $link = 'https://api.whatsapp.com/send?phone=' . $item['url']; break; } $link = apply_filters( 'astra_addon_author_social_sharing_link', $link, $item['id'] ); $aria_label = $item['label'] ? $item['label'] : $item['id']; $is_phone_or_email = 'phone' === $item['id'] || 'email' === $item['id']; $add_target = $is_phone_or_email ? '' : '_blank'; $add_rel = $is_phone_or_email ? '' : 'noopener noreferrer'; $icon_color = ! empty( $item['color'] ) ? $item['color'] : '#3a3a3a'; $icon_background_color = ! empty( $item['background'] ) ? $item['background'] : 'transparent'; $markup .= '
' . Astra_Builder_UI_Controller::fetch_svg_icon( in_array( $item['icon'], $social_icon_condition ) ? $item['icon'] . '-fill' : $item['icon'] ) . '
'; } } } $markup .= '
'; return $markup; } /** * Render social sharing. * * @since 4.1.0 */ public function astra_render_social_sharing() { $items = astra_get_option( 'single-post-social-sharing-icon-list' ); $items = isset( $items['items'] ) ? $items['items'] : array(); $post_categories = wp_strip_all_tags( get_the_category_list( ',' ) ); $post_title = get_the_title(); $post_link = urlencode( get_the_permalink() ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode $email_title = str_replace( '&', '%26', $post_title ); $enable_heading = astra_get_option( 'single-post-social-sharing-heading-enable' ); $heading_text = astra_get_option( 'single-post-social-sharing-heading-text' ); $heading_position = astra_get_option( 'single-post-social-sharing-heading-position' ); $show_label = astra_get_option( 'single-post-social-sharing-icon-label' ); $show_label_class = $show_label ? 'social-show-label-true' : 'social-show-label-false'; $color_type = astra_get_option( 'single-post-social-sharing-icon-color-type' ); $label_position = astra_get_option( 'single-post-social-sharing-icon-label-position' ); $social_icon_condition = array( 'facebook', 'pinterest', 'linkedin', 'reddit', 'whatsapp', 'sms' ); if ( $items ) { ob_start(); ?>

$post_link, ), 'https://www.facebook.com/sharer.php' ); break; case 'twitter': case 'twitter-x': $link = add_query_arg( array( 'url' => $post_link, 'text' => rawurlencode( html_entity_decode( wp_strip_all_tags( $post_title ), ENT_COMPAT, 'UTF-8' ) ), 'hashtags' => $post_categories, ), 'http://twitter.com/share' ); break; case 'email': $link = add_query_arg( array( 'subject' => wp_strip_all_tags( $email_title ), 'body' => $post_link, ), 'mailto:' ); break; case 'pinterest': $link = 'https://pinterest.com/pin/create/bookmarklet/?media=' . get_the_post_thumbnail_url() . '&url=' . $post_link . '&description=' . $post_title; break; case 'linkedin': $link = 'https://www.linkedin.com/shareArticle?mini=true&url=' . $post_link . '&title=' . urlencode( $post_title ) . '&source=' . urlencode( get_bloginfo( 'name' ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode break; case 'tumblr': $link = 'http://www.tumblr.com/share/link?url=' . $post_link . '&title=' . $post_title; break; case 'reddit': $link = 'https://reddit.com/submit?url=' . $post_link . '&title=' . $post_title; break; case 'whatsapp': $link = 'https://wa.me/?text=' . $post_link; break; case 'sms': $link = 'sms://?&body=' . $post_title . ' - ' . $post_link; break; case 'vk': $link = 'http://vk.com/share.php?url=' . urlencode( $post_link ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode break; case 'telegram': // The `Post_link` variable has already been encoded above. $link = 'https://t.me/share/url?url=' . $post_link . '&text=' . rawurlencode( $post_title ); break; } $aria_label = $item['label'] ? $item['label'] : $item['id']; $is_phone_or_email = 'phone' === $item['id'] || 'email' === $item['id']; $add_target = $is_phone_or_email ? '' : '_blank'; $add_rel = $is_phone_or_email ? '' : apply_filters( 'astra_social_rel_attribute', 'noopener noreferrer' ); ?>

true, ); } else { $term_args = array( 'hide_empty' => true, ); } } if ( is_tag() || ( is_home() && 'tags' === $blog_filter_by ) ) { $taxonomy_name = 'post_tag'; if ( isset( $tag_include ) ) { $term_args = array( 'hide_empty' => true, ); } else { $term_args = array( 'hide_empty' => true, ); } } $terms = get_terms( $taxonomy_name, $term_args ); // Get all terms of a taxonomy. if ( $terms && ! is_wp_error( $terms ) ) { if ( is_category() && 'tags' === $blog_filter_by ) { return false; } if ( is_tag() && 'categories' === $blog_filter_by ) { return false; } if ( is_category() && in_array( get_queried_object_id(), $category_include_array ) ) { return false; } if ( is_tag() && in_array( get_queried_object_id(), $tag_include_array ) ) { return false; } ob_start(); ?>