<?php
/**
 * Custom Functions.
 *
 * @package Always
 */

if( !function_exists( 'always_fonts_url' ) ) :

    //Google Fonts URL
    function always_fonts_url(){

        $font_families = array(
            'Smooch',
            'PT+Serif:ital,wght@0,400;0,700;1,400;1,700',
            'Inter:wght@300;400;500;600;700'

        );

        $fonts_url = add_query_arg( array(
            'family' => implode( '&family=', $font_families ),
            'display' => 'swap',
        ), 'https://fonts.googleapis.com/css2' );

        return esc_url_raw($fonts_url);

    }

endif;

if( !function_exists( 'always_social_menu_icon' ) ) :

    function always_social_menu_icon( $item_output, $item, $depth, $args ) {

        // Add Icon
        if ( 'always-social-menu' === $args->theme_location ) {

            $svg = Always_SVG_Icons::get_theme_svg_name( $item->url );

            if ( empty( $svg ) ) {
                $svg = always_the_theme_svg( 'link',$return = true );
            }

            $item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output );
        }

        return $item_output;
    }
    
endif;

add_filter( 'walker_nav_menu_start_el', 'always_social_menu_icon', 10, 4 );

if( !function_exists( 'always_add_sub_toggles_to_main_menu' ) ) :

    function always_add_sub_toggles_to_main_menu( $args, $item, $depth ) {

        // Add sub menu toggles to the Expanded Menu with toggles.
        if( isset( $args->show_toggles ) && $args->show_toggles ){

            // Wrap the menu item link contents in a div, used for positioning.
            $args->before = '<div class="submenu-wrapper">';
            $args->after  = '';

            // Add a toggle to items with children.
            if( in_array( 'menu-item-has-children', $item->classes, true ) ){

                $toggle_target_string = '.menu-item.menu-item-' . $item->ID . ' > .sub-menu';
                // Add the sub menu toggle.
                $args->after .= '<button class="toggle submenu-toggle" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="250" aria-expanded="false"><span class="btn__content" tabindex="-1"><span class="screen-reader-text">' . __( 'Show sub menu', 'always' ) . '</span>' . always_the_theme_svg( 'chevron-down',$return = true ) . '</span></button>';

            }

            // Close the wrapper.
            $args->after .= '</div><!-- .submenu-wrapper -->';

            // Add sub menu icons to the primary menu without toggles.
        }elseif( 'always-primary-menu' === $args->theme_location ){

            if( in_array( 'menu-item-has-children', $item->classes, true ) ){

                $args->after = '<span class="icon">'.always_the_theme_svg('chevron-down',true).'</span>';

            }else{

                $args->after = '';

            }
        }

        return $args;

    }

endif;

add_filter( 'nav_menu_item_args', 'always_add_sub_toggles_to_main_menu', 10, 3 );

if( !function_exists( 'always_sanitize_sidebar_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function always_sanitize_sidebar_option_meta( $input ){

        $metabox_options = array( 'global-sidebar','left-sidebar','right-sidebar','no-sidebar' );
        if( in_array( $input,$metabox_options ) ){

            return $input;

        }else{

            return '';

        }
    }

endif;

if( !function_exists( 'always_page_lists' ) ) :

    // Page List.
    function always_page_lists(){

        $page_lists = array();
        $page_lists[''] = esc_html__( '-- Select Page --','always' );
        $pages = get_pages();
        foreach( $pages as $page ){

            $page_lists[$page->ID] = $page->post_title;

        }
        return $page_lists;
    }

endif;

if( !function_exists( 'always_sanitize_post_layout_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function always_sanitize_post_layout_option_meta( $input ){

        $metabox_options = array( 'global-layout','layout-1','layout-2' );
        if( in_array( $input,$metabox_options ) ){

            return $input;

        }else{

            return '';

        }

    }

endif;

if( !function_exists( 'always_sanitize_header_overlay_option_meta' ) ) :

    // Sidebar Option Sanitize.
    function always_sanitize_header_overlay_option_meta( $input ){

        $metabox_options = array( 'global-layout','enable-overlay' );
        if( in_array( $input,$metabox_options ) ){

            return $input;

        }else{

            return '';

        }

    }

endif;

/**
 * Always SVG Icon helper functions
 *
 * @package Always
 * @since 1.0.0
 */
if ( ! function_exists( 'always_the_theme_svg' ) ):
    /**
     * Output and Get Theme SVG.
     * Output and get the SVG markup for an icon in the Always_SVG_Icons class.
     *
     * @param string $svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function always_the_theme_svg( $svg_name, $return = false ) {

        if( $return ){

            return always_get_theme_svg( $svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in always_get_theme_svg();.

        }else{

            echo always_get_theme_svg( $svg_name ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in always_get_theme_svg();.
            
        }
    }

endif;

if ( ! function_exists( 'always_get_theme_svg' ) ):

    /**
     * Get information about the SVG icon.
     *
     * @param string $svg_name The name of the icon.
     * @param string $group The group the icon belongs to.
     * @param string $color Color code.
     */
    function always_get_theme_svg( $svg_name ) {

        // Make sure that only our allowed tags and attributes are included.
        $svg = wp_kses(
            Always_SVG_Icons::get_svg( $svg_name ),
            array(
                'svg'     => array(
                    'class'       => true,
                    'xmlns'       => true,
                    'width'       => true,
                    'height'      => true,
                    'viewbox'     => true,
                    'aria-hidden' => true,
                    'role'        => true,
                    'focusable'   => true,
                ),
                'path'    => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'd'         => true,
                    'transform' => true,
                ),
                'polygon' => array(
                    'fill'      => true,
                    'fill-rule' => true,
                    'points'    => true,
                    'transform' => true,
                    'focusable' => true,
                ),
            )
        );
        if ( ! $svg ) {
            return false;
        }
        return $svg;

    }

endif;


if( !function_exists( 'always_post_category_list' ) ) :

    // Post Category List.
    function always_post_category_list( $select_cat = true ){

        $post_cat_lists = get_categories(
            array(
                'hide_empty' => '0',
                'exclude' => '1',
            )
        );

        $post_cat_cat_array = array();
        if( $select_cat ){

            $post_cat_cat_array[''] = esc_html__( '-- Select Category --','always' );

        }

        foreach ( $post_cat_lists as $post_cat_list ) {

            $post_cat_cat_array[$post_cat_list->slug] = $post_cat_list->name;

        }

        return $post_cat_cat_array;
    }

endif;

if( !function_exists('always_sanitize_meta_pagination') ):

    /** Sanitize Enable Disable Checkbox **/
    function always_sanitize_meta_pagination( $input ) {

        $valid_keys = array('global-layout','no-navigation','norma-navigation','ajax-next-post-load');
        if ( in_array( $input , $valid_keys ) ) {
            return $input;
        }
        return '';

    }

endif;

if( !function_exists('always_disable_post_views') ):

    /** Disable Post Views **/
    function always_disable_post_views() {

        add_filter('booster_extension_filter_views_ed', function ( ) {
            return false;
        });

    }

endif;

if( !function_exists('always_disable_post_read_time') ):

    /** Disable Read Time **/
    function always_disable_post_read_time() {

        add_filter('booster_extension_filter_readtime_ed', function ( ) {
            return false;
        });

    }

endif;

if( !function_exists('always_disable_post_like_dislike') ):

    /** Disable Like Dislike **/
    function always_disable_post_like_dislike() {

        add_filter('booster_extension_filter_like_ed', function ( ) {
            return false;
        });

    }

endif;

if( !function_exists('always_disable_post_author_box') ):

    /** Disable Author Box **/
    function always_disable_post_author_box() {

        add_filter('booster_extension_filter_ab_ed', function ( ) {
            return false;
        });

    }

endif;


add_filter('booster_extension_filter_ss_ed', function ( ) {
    return false;
});

if( !function_exists('always_disable_post_reaction') ):

    /** Disable Reaction **/
    function always_disable_post_reaction() {

        add_filter('booster_extension_filter_reaction_ed', function ( ) {
            return false;
        });

    }

endif;

if( !function_exists('always_post_floating_nav') ):

    function always_post_floating_nav(){

        $always_default = always_get_default_theme_options();
        $ed_floating_next_previous_nav = get_theme_mod( 'ed_floating_next_previous_nav',$always_default['ed_floating_next_previous_nav'] );

        if( 'post' === get_post_type() && $ed_floating_next_previous_nav ){

            $next_post = get_next_post();
            $prev_post = get_previous_post();

            if( isset( $prev_post->ID ) ){

                $prev_link = get_permalink( $prev_post->ID );?>

                <div class="floating-post-navigation floating-navigation-prev">
                    <?php if( get_the_post_thumbnail( $prev_post->ID,'medium' ) ){ ?>
                            <?php echo wp_kses_post( get_the_post_thumbnail( $prev_post->ID,'medium' ) ); ?>
                    <?php } ?>
                    <a href="<?php echo esc_url( $prev_link ); ?>">
                        <span class="floating-navigation-label"><?php echo esc_html__('Previous post', 'always'); ?></span>
                        <span class="floating-navigation-title"><?php echo esc_html( get_the_title( $prev_post->ID ) ); ?></span>
                    </a>
                </div>

            <?php }

            if( isset( $next_post->ID ) ){

                $next_link = get_permalink( $next_post->ID );?>

                <div class="floating-post-navigation floating-navigation-next">
                    <?php if( get_the_post_thumbnail( $next_post->ID,'medium' ) ){ ?>
                        <?php echo wp_kses_post( get_the_post_thumbnail( $next_post->ID,'medium' ) ); ?>
                    <?php } ?>
                    <a href="<?php echo esc_url( $next_link ); ?>">
                        <span class="floating-navigation-label"><?php echo esc_html__('Next post', 'always'); ?></span>
                        <span class="floating-navigation-title"><?php echo esc_html( get_the_title( $next_post->ID ) ); ?></span>
                    </a>
                </div>

            <?php
            }

        }

    }

endif;

add_action( 'always_navigation_action','always_post_floating_nav',10 );

if( !function_exists('always_single_post_navigation') ):

    function always_single_post_navigation(){

        $always_default = always_get_default_theme_options();
        $twp_navigation_type = esc_attr( get_post_meta( get_the_ID(), 'twp_disable_ajax_load_next_post', true ) );
        $current_id = '';
        $article_wrap_class = '';
        global $post;
        $current_id = $post->ID;
        if( $twp_navigation_type == '' || $twp_navigation_type == 'global-layout' ){
            $twp_navigation_type = get_theme_mod('twp_navigation_type', $always_default['twp_navigation_type']);
        }


        if( $twp_navigation_type != 'no-navigation' && 'post' === get_post_type() ){

            if( $twp_navigation_type == 'norma-navigation' ){ ?>

                <div class="theme-block navigation-wrapper">
                    <?php
                    // Previous/next post navigation.
                    the_post_navigation(array(
                        'prev_text' => '<span class="arrow" aria-hidden="true">' . always_the_theme_svg('arrow-left',$return = true ) . '</span><span class="screen-reader-text">' . __('Previous post:', 'always') . '</span><h4 class="entry-title entry-title-medium">%title</h4>',
                        'next_text' => '<span class="arrow" aria-hidden="true">' . always_the_theme_svg('arrow-right',$return = true ) . '</span><span class="screen-reader-text">' . __('Next post:', 'always') . '</span><h4 class="entry-title entry-title-medium">%title</h4>',
                    )); ?>
                </div>
                <?php

            }else{

                $next_post = get_next_post();
                if( isset( $next_post->ID ) ){

                    $next_post_id = $next_post->ID;
                    echo '<div loop-count="1" next-post="' . absint( $next_post_id ) . '" class="twp-single-infinity"></div>';

                }
            }

        }

    }

endif;

add_action( 'always_navigation_action','always_single_post_navigation',30 );

if ( ! function_exists( 'always_header_toggle_search' ) ):

    /**
     * Header Search
     **/
    function always_header_toggle_search() {

        $always_default = always_get_default_theme_options();
        $ed_header_search = get_theme_mod( 'ed_header_search', $always_default['ed_header_search'] );
        if( $ed_header_search ){ ?>

            <div class="header-searchbar">
                <div class="header-searchbar-inner">
                    <div class="wrapper">

                        <div class="header-searchbar-area">

                            <a href="javascript:void(0)" class="skip-link-search-start"></a>
                            
                            <?php get_search_form(); ?>

                            <button type="button" id="search-closer" class="exit-search">
                                <?php always_the_theme_svg('cross'); ?>
                            </button>

                            <a href="javascript:void(0)" class="skip-link-search-end"></a>

                        </div>



                    </div>
                </div>
            </div>

        <?php
        }

    }

endif;

add_action( 'always_before_footer_content_action','always_header_toggle_search',10 );

if( !function_exists('always_content_offcanvas') ):

    // Offcanvas Contents
    function always_content_offcanvas(){ ?>

        <div id="offcanvas-menu">
            <div class="offcanvas-wraper">

                <div class="close-offcanvas-menu">
                    <div class="offcanvas-close">

                        <a href="javascript:void(0)" class="skip-link-menu-start"></a>

                        <button type="button" class="button-offcanvas-close">
                            <?php always_the_theme_svg('close'); ?>
                        </button>

                    </div>
                </div>

                <div id="primary-nav-offcanvas" class="offcanvas-item offcanvas-main-navigation">
                    <nav class="primary-menu-wrapper" aria-label="<?php esc_attr_e('Horizontal', 'always'); ?>" role="navigation">
                        <ul class="primary-menu">

                            <?php
                            if( has_nav_menu('always-primary-menu') ){

                                wp_nav_menu(
                                    array(
                                        'container' => '',
                                        'items_wrap' => '%3$s',
                                        'theme_location' => 'always-primary-menu',
                                        'show_toggles' => true,
                                    )
                                );

                            }else{
                                
                                wp_list_pages(
                                    array(
                                        'match_menu_classes' => true,
                                        'show_sub_menu_icons' => false,
                                        'title_li' => false,
                                        'show_toggles' => true,
                                        'walker' => new Always_Walker_Page(),
                                    )
                                );
                            } ?>

                        </ul>
                    </nav><!-- .primary-menu-wrapper -->
                </div>

                <?php if( has_nav_menu('always-social-menu') ){ ?>

                    <div id="social-nav-offcanvas" class="offcanvas-item theme-social-navigation offcanvas-social-navigation">

                        <?php
                        wp_nav_menu(array(
                            'theme_location' => 'always-social-menu',
                            'link_before' => '<span class="screen-reader-text">',
                            'link_after' => '</span>',
                            'container' => 'div',
                            'container_class' => 'social-menu',
                            'depth' => 1,
                        )); ?>

                    </div>

                <?php } ?>

                <a href="javascript:void(0)" class="skip-link-menu-end"></a>

            </div>
        </div>

    <?php
    }

endif;

add_action( 'always_before_footer_content_action','always_content_offcanvas',30 );

if( !function_exists('always_footer_content_widget') ):

    function always_footer_content_widget(){

        $always_default = always_get_default_theme_options();
        if( is_active_sidebar('always-footer-widget-0') || 
            is_active_sidebar('always-footer-widget-1') || 
            is_active_sidebar('always-footer-widget-2') ):

            $x = 1;
            $footer_sidebar = 0;
            do {
                if ($x == 3 && is_active_sidebar('always-footer-widget-2')) {
                    $footer_sidebar++;
                }
                if ($x == 2 && is_active_sidebar('always-footer-widget-1')) {
                    $footer_sidebar++;
                }
                if ($x == 1 && is_active_sidebar('always-footer-widget-0')) {
                    $footer_sidebar++;
                }
                $x++;
            } while ($x <= 3);
            if ($footer_sidebar == 1) {
                $footer_sidebar_class = 12;
            } elseif ($footer_sidebar == 2) {
                $footer_sidebar_class = 6;
            } else {
                $footer_sidebar_class = 4;
            }
            $footer_column_layout = absint(get_theme_mod('footer_column_layout', $always_default['footer_column_layout'])); ?>

            <div class="footer-widgetarea">
                <div class="wrapper">
                    <div class="wrapper-inner">

                        <?php if (is_active_sidebar('always-footer-widget-0')): ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-12">
                                <?php dynamic_sidebar('always-footer-widget-0'); ?>
                            </div>
                        <?php endif; ?>

                        <?php if (is_active_sidebar('always-footer-widget-1')): ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-12">
                                <?php dynamic_sidebar('always-footer-widget-1'); ?>
                            </div>
                        <?php endif; ?>

                        <?php if (is_active_sidebar('always-footer-widget-2')): ?>
                            <div class="column <?php echo 'column-' . absint($footer_sidebar_class); ?> column-sm-12">
                                <?php dynamic_sidebar('always-footer-widget-2'); ?>
                            </div>
                        <?php endif; ?>

                    </div>
                </div>
            </div>

        <?php
        endif;

    }

endif;

add_action( 'always_footer_content_action','always_footer_content_widget',10 );


if( !function_exists('always_footer_content_info') ):

    /**
     * Footer Copyright Area
    **/
    function always_footer_content_info(){

        $always_default = always_get_default_theme_options(); ?>
        <div class="site-info">
            <div class="wrapper">
                <?php do_action('always_footer_content_logo'); ?>
                <?php do_action('always_footer_content_social_nav'); ?>
                <div class="footer-credits">

                    <div class="footer-copyright">
                        <?php
                        $ed_footer_copyright = wp_kses_post(get_theme_mod('ed_footer_copyright', $always_default['ed_footer_copyright']));
                        $footer_copyright_text = wp_kses_post(get_theme_mod('footer_copyright_text', $always_default['footer_copyright_text']));

                        echo esc_html__('Copyright ', 'always') . '&copy ' . absint(date('Y')) . ' <a href="' . esc_url(home_url('/')) . '" title="' . esc_attr(get_bloginfo('name', 'display')) . '" ><span>' . esc_html(get_bloginfo('name', 'display')) . '. </span></a> ' . esc_html($footer_copyright_text);

                        if ($ed_footer_copyright) {

                            echo '<br>';
                            echo esc_html__('Theme: ', 'always') . 'Always ' . esc_html__('By ', 'always') . '<a href="' . esc_url('https://www.themeinwp.com/theme/always') . '"  title="' . esc_attr__('Themeinwp', 'always') . '" target="_blank" rel="author"><span>' . esc_html__('Themeinwp. ', 'always') . '</span></a>';

                            echo esc_html__('Powered by ', 'always') . '<a href="' . esc_url('https://wordpress.org') . '" title="' . esc_attr__('WordPress', 'always') . '" target="_blank"><span>' . esc_html__('WordPress.', 'always') . '</span></a>';

                        } ?>

                    </div>
                </div>

            </div>
        </div>

    <?php
    }

endif;

add_action( 'always_footer_content_action','always_footer_content_info',20 );


if( ! function_exists( 'always_iframe_escape' ) ):
    
    /** Escape Iframe **/
    function always_iframe_escape( $input ){

        $all_tags = array(
            'iframe'=>array(
                'width'=>array(),
                'height'=>array(),
                'src'=>array(),
                'frameborder'=>array(),
                'allow'=>array(),
                'allowfullscreen'=>array(),
            ),
            'video'=>array(
                'width'=>array(),
                'height'=>array(),
                'src'=>array(),
                'style'=>array(),
                'controls'=>array(),
            )
        );

        return wp_kses($input,$all_tags);
        
    }

endif;

if( class_exists( 'Booster_Extension_Class' ) ){

    add_filter('booster_extemsion_content_after_filter','always_after_content_pagination');

}

if( !function_exists('always_after_content_pagination') ):

    function always_after_content_pagination($after_content){

        $pagination_single = wp_link_pages( array(
                    'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'always' ),
                    'after'  => '</div>',
                    'echo' => false
                ) );

        $after_content =  $pagination_single.$after_content;

        return $after_content;

    }

endif;

if( !function_exists('always_excerpt_content') ):

    function always_excerpt_content(){ 

        $always_default = always_get_default_theme_options();
        $ed_post_excerpt = get_theme_mod( 'ed_post_excerpt',$always_default['ed_post_excerpt'] );

        if( $ed_post_excerpt ){ ?>
                    
            <div class="entry-content">

                <?php
                if( has_excerpt() ){

                    the_excerpt();

                }else{

                    echo esc_html( wp_trim_words( get_the_content(), 25, '...' ) );

                } ?>

            </div>

        <?php }
    }

endif;

/**
 * Print the first instance of a block in the content, and then break away.
 *
 * @since always 1.0
 *
 * @param string      $block_name The full block type name, or a partial match.
 *                                Example: `core/image`, `core-embed/*`.
 * @param string|null $content    The content to search in. Use null for get_the_content().
 * @param int         $instances  How many instances of the block will be printed (max). Default  1.
 * @return bool Returns true if a block was located & printed, otherwise false.
 */
function always_print_first_instance_of_block( $block_name, $content = null, $instances = 1 ) {
    $instances_count = 0;
    $blocks_content  = '';

    if ( ! $content ) {
        $content = get_the_content();
    }

    // Parse blocks in the content.
    $blocks = parse_blocks( $content );

    // Loop blocks.
    foreach ( $blocks as $block ) {

        // Sanity check.
        if ( ! isset( $block['blockName'] ) ) {
            continue;
        }

        // Check if this the block matches the $block_name.
        $is_matching_block = false;

        // If the block ends with *, try to match the first portion.
        if ( '*' === $block_name[-1] ) {
            $is_matching_block = 0 === strpos( $block['blockName'], rtrim( $block_name, '*' ) );
        } else {
            $is_matching_block = $block_name === $block['blockName'];
        }

        if ( $is_matching_block ) {
            // Increment count.
            $instances_count++;

            // Add the block HTML.
            $blocks_content .= render_block( $block );

            // Break the loop if the $instances count was reached.
            if ( $instances_count >= $instances ) {
                break;
            }
        }
    }

    if ( $blocks_content ) {
        /** This filter is documented in wp-includes/post-template.php */
        echo apply_filters( 'the_content', $blocks_content ); // phpcs:ignore WordPress.Security.EscapeOutput
        return true;
    }

    return false;
}

if (!function_exists('always_banner_slider_section')):
    // Single Posts Related Posts.
    function always_banner_slider_section()
    {
        $always_default = always_get_default_theme_options();
        $ed_banner_slider_section = get_theme_mod('ed_banner_slider_section', $always_default['ed_banner_slider_section']);
        $ed_banner_slider_wide_layout_section = get_theme_mod('ed_banner_slider_wide_layout_section', $always_default['ed_banner_slider_wide_layout_section']);
        if ($ed_banner_slider_section) {
            $mg_banner_slider_section_cat = get_theme_mod('mg_banner_slider_section_cat');
            $ed_banner_slider_autoplay = get_theme_mod('ed_banner_slider_autoplay', $always_default['ed_banner_slider_autoplay']);
            $ed_banner_slider_arrow = get_theme_mod('ed_banner_slider_arrow', $always_default['ed_banner_slider_arrow']);
            $ed_banner_slider_dots = get_theme_mod('ed_banner_slider_dots', $always_default['ed_banner_slider_dots']);
            if ($ed_banner_slider_autoplay) {
                $autoplay = 'true';
            } else {
                $autoplay = 'false';
            }
            if ($ed_banner_slider_arrow) {
                $arrow = 'true';
            } else {
                $arrow = 'false';
            }
            if ($ed_banner_slider_dots) {
                $dots = 'true';
            } else {
                $dots = 'false';
            }
            if (is_rtl()) {
                $rtl = 'true';
            } else {
                $rtl = 'false';
            }
            $banner_slider_posts_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 5, 'category_name' => $mg_banner_slider_section_cat, 'post__not_in' => get_option("sticky_posts")));
            if ($banner_slider_posts_query->have_posts()): ?>
                <?php 
                $twp_slider_class = '';
                if ($ed_banner_slider_wide_layout_section) {
                    $twp_slider_class = 'wide-banner-slider';
                } ?>
                <div class="theme-block theme-block-banner-slider">
                    <div class="wrapper">
                        <div class="wrapper-inner">
                            <div class="column column-12">

                                <div class="theme-banner-slider <?php echo $twp_slider_class; ?>" data-slick='{"autoplay": <?php echo esc_attr($autoplay); ?>, "arrows": <?php echo esc_attr($arrow); ?>, "dots": <?php echo esc_attr($dots); ?>, "rtl": <?php echo esc_attr($rtl); ?>}'>
                                    <?php
                                    while ($banner_slider_posts_query->have_posts()):
                                        $banner_slider_posts_query->the_post(); ?>


                                            <article id="post-<?php the_ID(); ?>" <?php post_class('theme-blog-article theme-banner-article'); ?>>

                                                    <?php
                                                    $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                                                    $featured_image = isset($featured_image[0]) ? $featured_image[0] : ''; ?>
                                                    <div class="entry-thumbnail">
                                                        <a href="<?php the_permalink(); ?>" class="data-bg data-bg-large"
                                                           data-background="<?php echo esc_url($featured_image); ?>"></a>
                                                    </div>
                                                    <div class="post-content">
                                                        <header class="entry-header">
                                                            <h3 class="entry-title entry-title-big">
                                                                <a href="<?php the_permalink(); ?>">
                                                                    <?php the_title(); ?>
                                                                </a>
                                                            </h3>
                                                        </header>
                                                        <div class="entry-meta">
                                                            <?php
                                                            always_posted_by();
                                                            always_posted_on();
                                                            ?>
                                                        </div>

                                                        <?php always_excerpt_content(); ?>
                                                    </div>

                                            </article>

                                    <?php
                                    endwhile; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php
                wp_reset_postdata();
            endif;
        }
    }
endif;


if( !function_exists( 'always_cta_section' ) ) :

    function always_cta_section(){
        $always_default = always_get_default_theme_options();
        $ed_cta_section = get_theme_mod( 'ed_cta_section', $always_default['ed_cta_section'] );
        $ed_cta_post_excerpt = get_theme_mod( 'ed_cta_post_excerpt', $always_default['ed_cta_post_excerpt'] );
        if ($ed_cta_section) {
        $always_cta_page = esc_attr(get_theme_mod('select_page_for_cta'));
        if (!empty($always_cta_page)) {
            $always_cta_page_args = array(
                'post_type' => 'page',
                'page_id' => $always_cta_page,
            );
        }
        $homepage_cta_button_text = get_theme_mod( 'homepage_cta_button_text',$always_default['homepage_cta_button_text'] );
        $homepage_cta_button_text_url = get_theme_mod( 'homepage_cta_button_text_url',$always_default['homepage_cta_button_text_url'] );
        $cta_link_tab = get_theme_mod( 'cta_link_tab',$always_default['cta_link_tab'] );
        $ed_cta_image_overlay = get_theme_mod( 'ed_cta_image_overlay',$always_default['ed_cta_image_overlay'] );
        if (!empty($always_cta_page_args)) {
            $always_cta_page_query = new WP_Query($always_cta_page_args);
            while ($always_cta_page_query->have_posts()): $always_cta_page_query->the_post();
                $url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                $url = isset($url[0]) ? $url[0] : ''; 
                ?>
                <div class="theme-block theme-block-cta">
                    <div class="theme-pattern-design round-pattern-left">
                        <?php always_the_theme_svg('round-pattern-left'); ?>
                    </div>
                    <div class="wrapper">
                        <div class="theme-cta-panel <?php if ($url){ echo 'data-bg';} ?>" data-background="<?php echo esc_url($url); ?>">
                            <?php if($ed_cta_image_overlay){ ?>
                                <div class="data-bg-overlay"></div>
                            <?php } ?>
                            <div class="wrapper-inner">
                                <div class="column column-8 column-sm-12">
                                    <div class="cta-panel">
                                         <div class="cta-panel-header">
                                             <h2 class="theme-block-title theme-block-title-large">
                                                 <?php the_title();?>
                                             </h2>
                                         </div>
                                         <?php if ($ed_cta_post_excerpt) { ?>
                                            <div class="cta-panel-content">
                                                <?php the_excerpt(); ?>
                                            </div>
                                         <?php } ?>
                                    </div>
                                </div>
                                 <div class="column column-4 column-sm-12">

                                    <?php
                                    if ($homepage_cta_button_text) { ?>
                                        <div class="theme-block-link">
                                            <a href="<?php echo esc_url($homepage_cta_button_text_url); ?>" class="theme-button" <?php if($cta_link_tab){ ?>target="_blank"<?php } ?>>
                                                <span><?php echo esc_html($homepage_cta_button_text); ?></span>
                                                <span><?php always_the_theme_svg('arrow-right-long'); ?></span>
                                            </a>
                                        </div>
                                    <?php } ?>
                                 </div>
                            </div>
                        </div>
                    </div>
                    <div class="theme-pattern-design round-pattern-right">
                        <?php always_the_theme_svg('round-pattern-right'); ?>
                    </div>
                </div>
            <?php endwhile;
            wp_reset_postdata();
        }
        }
    }

endif;



if( !function_exists( 'always_about_section' ) ) :

    function always_about_section(){
        $always_default = always_get_default_theme_options();
        $ed_about_section = get_theme_mod( 'ed_about_section', $always_default['ed_about_section'] );
        $ed_about_featured_section = get_theme_mod( 'ed_about_featured_section', $always_default['ed_about_featured_section'] );
        $homepage_about_title = get_theme_mod( 'about_section_title',$always_default['about_section_title'] );
        if ($ed_about_section) {
        $always_about_page = esc_attr(get_theme_mod('select_page_for_about'));
        if (!empty($always_about_page)) {
            $always_about_page_args = array(
                'post_type' => 'page',
                'page_id' => $always_about_page,
            );
        }
        if (!empty($always_about_page_args)) {
            $always_about_page_query = new WP_Query($always_about_page_args);
            while ($always_about_page_query->have_posts()): $always_about_page_query->the_post();
                if (has_post_thumbnail()) { 
                    $url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                    $url = isset($url[0]) ? $url[0] : ''; 
                }
                ?>

                <div class="theme-block theme-block-bg theme-block-about">
                    <div class="wrapper wrapper-small">
                        <div class="wrapper-inner">

                            <?php if (has_post_thumbnail()) {
                                $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'medium_large');
                                $featured_image = isset($featured_image[0]) ? $featured_image[0] : ''; ?>
                                <div class="column column-5 column-sm-12">
                                    <div class="entry-thumbnail mb-sm-20">
                                        <a href="<?php the_permalink(); ?>">
                                            <span class="data-bg data-bg-big" data-background="<?php echo esc_url($featured_image); ?>"></span>
                                        </a>
                                    </div>
                                </div>
                            <?php } ?>

                            <div class="column column-7 column-sm-12 text-center">
                                <div class="theme-section-heading section-heading-1">
                                    <h2 class="theme-section-title alt-font">
                                        <?php echo esc_html($homepage_about_title); ?>
                                    </h2>

                                    <div class="theme-section-subtext">
                                            <?php the_title(); ?>
                                    </div>
                                </div>

                                <div class="post-content">
                                    <?php if (has_excerpt()) {
                                        the_excerpt();
                                        always_read_more_page_render();
                                    } else {
                                        the_excerpt();
                                    } ?>
                                </div>

                                <a href="<?php the_permalink();?>" class="theme-button">
                                    <span><?php esc_html_e('Read the whole story', 'always'); ?></span>
                                    <span><?php always_the_theme_svg('arrow-right-long'); ?></span>
                                </a>

                            </div>
                        </div>
                    </div>
                    <?php if ($ed_about_featured_section) { ?>
                        <div class="wrapper wrapper-small mt-40">
                            <div class="wrapper-inner wrapper-inner-center">
                                <div class="column column-3 column-sm-12">
                                    <h4 class="primary-font featured-brands-title">
                                        <?php echo esc_html(get_theme_mod('about_section_featured_title'), $always_default['about_section_featured_title']); ?>
                                    </h4>
                                </div>
                                <div class="column column-9 column-sm-12">
                                    <div class="theme-featured-brands">
                                        <?php for ($i=1; $i < 5; $i++) { ?>
                                            <?php if (!empty(get_theme_mod('icon_uploader_about_section_'.$i)) ) { ?>
                                                <a href="<?php echo esc_url(get_theme_mod('icon_about_section_url_'.$i)); ?>" target="_blank">
                                                    <img src="<?php echo esc_url(get_theme_mod('icon_uploader_about_section_'.$i)); ?>">
                                                </a>
                                            <?php } ?>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php } ?>

                </div>

            <?php endwhile;
            wp_reset_postdata();
        }
        }
    }

endif;



if( !function_exists( 'always_contact_section' ) ) :

    function always_contact_section(){
        $always_default = always_get_default_theme_options();
        $ed_contact_section = get_theme_mod( 'ed_contact_section', $always_default['ed_contact_section'] );
        $contact_section_title = get_theme_mod( 'contact_section_title', $always_default['contact_section_title'] );
        $contact_section_location = get_theme_mod( 'contact_section_location', $always_default['contact_section_location'] );
        $contact_section_email = get_theme_mod( 'contact_section_email', $always_default['contact_section_email'] );
        $contact_section_number = get_theme_mod( 'contact_section_number', $always_default['contact_section_number'] );
        $contact_form_shortcode = get_theme_mod( 'contact_form_shortcode' );
        $contact_section_bg_image = get_theme_mod( 'contact_section_bg_image');
        if ($ed_contact_section) { ?>
            <div class="theme-block theme-block-contact theme-block-nospace">
                <div class="theme-block-contact-upper data-bg data-bg-fixed" <?php if ($contact_section_bg_image) { ?> data-background="<?php echo esc_url($contact_section_bg_image); ?>" <?php } ?>>
                    <div class="data-bg-overlay"></div>
                    <div class="wrapper-small text-center">
                        <?php $page_for_contact = esc_attr(get_theme_mod('select_page_for_contact'));
                        if (!empty($page_for_contact)) {
                            $page_for_contact_args = array(
                                'post_type' => 'page',
                                'page_id' => $page_for_contact,
                            );
                        }
                        if (!empty($page_for_contact_args)) {
                            $page_for_contact_query = new WP_Query($page_for_contact_args);
                            while ($page_for_contact_query->have_posts()): $page_for_contact_query->the_post();
                                ?>
                                <div class="theme-section-heading section-heading-1">
                                    <h2 class="theme-section-title alt-font">
                                        <?php echo esc_html($contact_section_title); ?>
                                    </h2>
                                    <div class="theme-section-subtext">
                                        <?php the_title(); ?>
                                    </div>
                                </div>
                                <div class="post-content">
                                    <?php if (has_excerpt()) {
                                        the_excerpt();
                                        always_read_more_page_render();
                                    } else {
                                        the_excerpt();
                                    } ?>
                                </div>
                                <a href="<?php the_permalink(); ?>" class="theme-button-primary">
                                    <span><?php esc_html_e('Reach out to us', 'always'); ?></span>
                                    <span><?php always_the_theme_svg('arrow-right-long'); ?></span>
                                </a>

                            <?php endwhile;
                            wp_reset_postdata();
                        } else { ?>
                            <div class="theme-section-heading section-heading-1">
                                <h2 class="theme-section-title alt-font">
                                    <?php echo esc_html($contact_section_title); ?>
                                </h2>
                            </div>
                        <?php } ?>
                    </div>
                </div>

                <div class="theme-block-contact-lower">
                    <div class="wrapper-inner">
                        <div class="column column-6 column-sm-12">
                            <div class="theme-block-heading">
                                <h3 class="theme-block-title theme-block-title-medium">
                                    <?php echo esc_html__('Send Us A Message', 'always') ?>
                                </h3>
                            </div>
                            <ul class="theme-contact-list">
                                <?php if ($contact_section_location) { ?>
                                    <li class="theme-contact-list-group">
                                        <div class="theme-contact-list-title">
                                            <?php echo esc_html__('Location:', 'always') ?>
                                        </div>
                                        <div class="theme-contact-list-content">
                                            <?php echo esc_html($contact_section_location); ?>
                                        </div>
                                    </li>
                                <?php } ?>

                                <li class="theme-contact-list-group">
                                    <?php if (!empty($contact_section_number) || !empty($contact_section_email)) { ?>
                                        <div class="theme-contact-list-title">
                                            <?php echo esc_html__('Contact:', 'always') ?>
                                        </div>
                                    <?php } ?>
                                    <div class="theme-contact-list-content">
                                        <?php if ($contact_section_number) { ?>
                                            <div class="contact-list-content-phone">
                                                <div class="contact-list-content-icon">

                                                </div>
                                                <div class="contact-list-content-detail">

                                                    <a href="tel:<?php echo absint($contact_section_number); ?>">
                                                        <?php echo absint($contact_section_number); ?>
                                                    </a>
                                                </div>
                                            </div>
                                        <?php } ?>
                                        <?php if ($contact_section_email) { ?>
                                            <div class="contact-list-content-email">
                                                <div class="contact-list-content-icon">

                                                </div>
                                                <div class="contact-list-content-detail">
                                                    <a href="mailto:someone@example.com">
                                                        <?php echo sanitize_email($contact_section_email); ?>
                                                    </a>
                                                </div>
                                            </div>
                                        <?php } ?>
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class="column column-6 column-sm-12">
                            <div class="post-content">
                                <?php echo do_shortcode($contact_form_shortcode); ?>
                            </div>
                        </div>

                        <?php if (has_nav_menu('always-social-menu')) { ?>
                            <div class="column column-12">
                                <div class="theme-contact-list-title">
                                    <?php echo esc_html__('Follow Us On:', 'always') ?>
                                </div>
                                <div class="theme-social-navigation theme-contact-list-content">
                                    <?php wp_nav_menu(array(
                                        'theme_location' => 'always-social-menu',
                                        'link_before' => '<span class="screen-reader-text">',
                                        'link_after' => '</span>',
                                        'container' => 'div',
                                        'container_class' => 'social-menu',
                                        'depth' => 1,
                                    )); ?>
                                </div>
                            </div>
                        <?php } ?>

                    </div>

                </div>
            </div>

        <?php }
    }

endif;



if( !function_exists( 'always_category_section' ) ) :

    function always_category_section(){
        $always_default = always_get_default_theme_options();
        $ed_category_section = get_theme_mod( 'ed_category_section', $always_default['ed_category_section'] );
        $homepage_category_section_title = get_theme_mod( 'homepage_category_section_title');
        $homepage_category_section_description = get_theme_mod( 'homepage_category_section_description');
        $homepage_category_button_text = get_theme_mod( 'homepage_category_button_text', $always_default['homepage_category_button_text'] );
        $homepage_category_button_text_url = get_theme_mod( 'homepage_category_button_text_url', $always_default['homepage_category_button_text_url'] );
        $ed_category_description = get_theme_mod( 'ed_category_description', $always_default['ed_category_description'] );
        if ($ed_category_section) { ?>
            <div class="theme-block theme-block-categories theme-block-bg theme-block-space-large theme-block-bg-1">
                <div class="theme-wave-seperator wave-seperator-up">
                    <?php always_the_theme_svg('wave-path'); ?>
                </div>
                <div class="wrapper">



                        <div class="theme-section-heading section-heading-1">
                            <?php if ($homepage_category_section_title) { ?>
                            <h2 class="theme-section-title">
                                <?php echo esc_html($homepage_category_section_title); ?>
                            </h2>
                            <?php } ?>

                            <?php if ($homepage_category_section_description) { ?>
                                <div class="theme-section-subtext">
                                    <?php echo esc_html($homepage_category_section_description); ?>
                                </div>
                            <?php } ?>

                            <?php if ($homepage_category_button_text) { ?>
                                <a href="<?php echo esc_url($homepage_category_button_text_url);?>" class="theme-button-primary">
                                    <span><?php echo esc_html($homepage_category_button_text);?></span>
                                    <span><?php always_the_theme_svg('arrow-right-long'); ?></span>
                                </a>
                            <?php } ?>
                        </div>




                    <div class="theme-categories-panels">
                        <div class="wrapper-inner wrapper-inner-large">
                            <?php for ($i=1; $i <= 3; $i++) { 
                                $always_get_cat_id = absint(get_theme_mod('select_category_for_cat_list_'.$i));
                                $twp_term_image = get_term_meta( $always_get_cat_id, 'twp-term-featured-image', true );
                                $twp_cat_link = get_category_link($always_get_cat_id);
                                $twp_cat_description = category_description($always_get_cat_id);
                                ?>
                                    <div class="column column-4 column-sm-12">
                                        <div class="categories-panel">

                                            <div class="categories-panel-header">

                                                <?php if ($twp_term_image) { ?>
                                                    <div class="category-panel-image <?php if ($twp_term_image){ echo 'data-bg data-bg-medium';} ?>" data-background="<?php echo esc_url($twp_term_image); ?>">
                                                        <?php if ( get_theme_mod('ed_category_image_overlay') == 1) { ?>
                                                            <div class="data-bg-overlay"></div>
                                                        <?php } ?>

                                                        <div class="theme-block-link">
                                                            <a href="<?php echo esc_url($twp_cat_link); ?>" class="theme-button-creative">
                                                                <?php esc_html_e('Learn More', 'always'); ?>
                                                            </a>
                                                        </div>
                                                    </div>
                                                <?php } ?>

                                            </div>

                                            <div class="categories-panel-content">
                                                <h2 class="theme-block-title">
                                                    <a href="<?php echo esc_url($twp_cat_link); ?>">
                                                        <?php echo esc_html(get_cat_name( $always_get_cat_id));?>
                                                    </a>
                                                </h2>
                                                <?php if (($ed_category_description == 1) && !empty($twp_cat_description)) { ?>
                                                    <div class="categories-panel-description">
                                                        <?php echo wp_kses_post($twp_cat_description); ?>
                                                    </div>

                                                <?php } ?>
                                               

                                            </div>
                                        </div>
                                    </div>
                            <?php  } ?>
                        </div>
                    </div>
                </div>

                <div class="theme-wave-seperator wave-seperator-down">
                    <?php always_the_theme_svg('wave-path'); ?>
                </div>
            </div>
        <?php }
    }

endif;



if( !function_exists( 'always_popup_newsletter' ) ) :

    function always_popup_newsletter(){

        $always_default = always_get_default_theme_options();
        $ed_mailchimp_newsletter = get_theme_mod( 'ed_mailchimp_newsletter',$always_default['ed_mailchimp_newsletter'] );
        $ed_mailchimp_newsletter_first_loading_only = get_theme_mod( 'ed_mailchimp_newsletter_first_loading_only',$always_default['ed_mailchimp_newsletter_first_loading_only'] );

        if( $ed_mailchimp_newsletter_first_loading_only && isset( $_COOKIE['BlogExpress_Visited'] ) && $_COOKIE['BlogExpress_Visited'] == 'true' ){

            $visited = false;

        }else{

            $visited = true;
            
        }

        if( $visited && $ed_mailchimp_newsletter ){

            $ed_mailchimp_newsletter_home_only = get_theme_mod( 'ed_mailchimp_newsletter_home_only',$always_default['ed_mailchimp_newsletter_home_only'] );
            $twp_mailchimp_shortcode = get_theme_mod( 'twp_mailchimp_shortcode' );
            $twp_newsletter_title = get_theme_mod( 'twp_newsletter_title',$always_default['twp_newsletter_title'] );
            $twp_newsletter_desc = get_theme_mod( 'twp_newsletter_desc',$always_default['twp_newsletter_desc'] );
            $twp_newsletter_image = get_theme_mod( 'twp_newsletter_image' );

            if( $ed_mailchimp_newsletter_home_only){

                if( is_home() || is_front_page() ){
                    $load_pages = true;
                }else{
                    $load_pages = false;
                }

            }else{
                $load_pages = true;
            }

            if( $load_pages ){ ?>

                <div class="twp-modal <?php if( $ed_mailchimp_newsletter_first_loading_only ){ echo 'single-load'; }else{ echo 'always-load'; } ?>">

                    <div class="twp-modal-overlay twp-modal-toggle"></div>

                    <div class="twp-modal-wrapper twp-modal-transition">
                        <div class="twp-modal-body">
                            <div class="newsletter-content-wrapper">
                                <div class="newsletter-image">
                                    <div class="data-bg data-bg-large"
                                         data-background="<?php echo esc_url( $twp_newsletter_image ); ?>">
                                    </div>
                                </div>
                                <div class="newsletter-content">
                                    <button class="twp-modal-close twp-modal-toggle">
                                        <?php always_the_theme_svg('cross'); ?>
                                    </button>
                                    <div class="newsletter-content-details">

                                        <?php if( $twp_newsletter_title ){ ?>
                                            <h3><?php echo esc_html( $twp_newsletter_title ); ?></h3>
                                        <?php } ?>

                                        <?php if( $twp_newsletter_desc ){ ?>
                                            <div class="newsletter-content-excerpt"><?php echo esc_html( $twp_newsletter_desc ); ?></div>
                                        <?php } ?>

                                        <?php if( $twp_mailchimp_shortcode ){ ?>
                                            <div class="mailchimp-form-wrapper">
                                                <?php echo do_shortcode($twp_mailchimp_shortcode); ?>
                                            </div>
                                        <?php } ?>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            <?php
            }

        }

    }

endif;

add_action('always_before_footer_content_action','always_popup_newsletter',30);


if( !function_exists( 'always_newsletter_section' ) ) :

    function always_newsletter_section(){

        $always_default = always_get_default_theme_options();
        $ed_mailchimp_newsletter_section = get_theme_mod( 'ed_mailchimp_newsletter_section',$always_default['ed_mailchimp_newsletter_section'] );

        $newsletter_ed = true;

        if( $newsletter_ed && $ed_mailchimp_newsletter_section ){

            $twp_newsletter_title_section = get_theme_mod( 'twp_newsletter_title_section',$always_default['twp_newsletter_title_section'] );
            $twp_newsletter_desc_section = get_theme_mod( 'twp_newsletter_desc_section',$always_default['twp_newsletter_desc_section'] );
            $twp_mailchimp_shortcode_section = get_theme_mod('twp_mailchimp_shortcode_section');
            ?>

            <div class="theme-block theme-block-newsletter">
                <div class="wrapper">

                    <div class="twp-newsletter-content">

                        <div class="theme-section-heading section-heading-1">
                            <?php if( $twp_newsletter_title_section ){ ?>
                                <h2 class="theme-section-title">
                                    <?php echo esc_html ( $twp_newsletter_title_section ); ?>
                                </h2>
                            <?php } ?>

                            <?php if( $twp_newsletter_desc_section ){ ?>
                                <div class="theme-section-subtext">
                                    <?php echo esc_html ( $twp_newsletter_desc_section ); ?>
                                </div>
                            <?php } ?>
                        </div>

                        <?php if( $twp_mailchimp_shortcode_section ){ ?>
                            <div class="twp-newsletter-form">
                                <?php echo do_shortcode( $twp_mailchimp_shortcode_section ); ?>
                            </div>
                        <?php } ?>

                    </div>

                </div>
            </div>

            <?php
        }

    }

endif;


if( !function_exists( 'always_related_post_section' ) ) :

    function always_related_post_section(){
        $always_default = always_get_default_theme_options();
        $ed_related_post = get_theme_mod( 'ed_related_post', $always_default['ed_related_post'] );
        $homepage_relate_post_button_text = get_theme_mod( 'homepage_relate_post_button_text', $always_default['homepage_relate_post_button_text'] );
        $homepage_relate_post_button_text_url = get_theme_mod( 'homepage_relate_post_button_text_url', $always_default['homepage_relate_post_button_text_url'] );
        $always_related_post_cat = get_theme_mod('always_related_post_cat');
        if ($ed_related_post) {
            $related_posts_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 4, 'category_name' => $always_related_post_cat, 'post__not_in' => get_option("sticky_posts"))); ?>
            <div class="theme-block theme-block-recommendation">
                <div class="wrapper">
                    <div class="wrapper-inner">
                    <?php if ($related_posts_query->have_posts()): ?>
                        <?php
                        $count = 1;
                        while ($related_posts_query->have_posts()):
                            $related_posts_query->the_post(); ?>

                                    <?php if ($count == 1) { ?>
                                    <div class="column column-8 column-sm-12">

                                        <article id="post-<?php the_ID(); ?>" <?php post_class('theme-related-article-main'); ?>>
                                            <div class="wrapper-inner">
                                                <?php
                                                $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                                                $featured_image = isset($featured_image[0]) ? $featured_image[0] : ''; ?>
                                                <div class="column column-5 column-xs-12">
                                                    <div class="entry-thumbnail">
                                                        <a href="<?php the_permalink(); ?>" class="data-bg data-bg-big"
                                                           data-background="<?php echo esc_url($featured_image); ?>"></a>
                                                    </div>
                                                </div>
                                                <div class="column column-7 column-xs-12">
                                                    <div class="theme-flexbox-panel">
                                                        <header class="entry-header">
                                                            <h3 class="entry-title entry-title-big">
                                                                <a href="<?php the_permalink(); ?>">
                                                                    <?php the_title(); ?>
                                                                </a>
                                                            </h3>
                                                            <div class="entry-meta">
                                                                <?php always_posted_by(); ?>
                                                            </div>
                                                        </header>
                                                        <div class="post-content">
                                                            <?php always_excerpt_content(); ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </article>
                                    </div>
                                    <div class="column column-4 column-sm-12">
                                        <div class="wrapper-list">
                                            <?php $count++;
                                            } else { ?>
                                                <article id="post-<?php the_ID(); ?>" <?php post_class('theme-related-article-list'); ?>>
                                                    <header class="entry-header">
                                                        <h3 class="entry-title entry-title-medium">
                                                            <a href="<?php the_permalink(); ?>">
                                                                <?php the_title(); ?>
                                                            </a>
                                                        </h3>
                                                    </header>
                                                    <div class="post-content">
                                                        <div class="entry-meta">
                                                            <?php
                                                            always_posted_by();
                                                            ?>
                                                        </div>
                                                    </div>
                                                </article>

                                            <?php if ($related_posts_query->current_post + 1 == $related_posts_query->post_count) { ?>
                                                <?php if ($homepage_relate_post_button_text) { ?>
                                                    <a href="<?php echo esc_url($homepage_relate_post_button_text_url); ?>" class="theme-button-primary">
                                                        <span><?php echo esc_html($homepage_relate_post_button_text); ?></span>
                                                        <span><?php always_the_theme_svg('arrow-right-long'); ?></span>
                                                    </a>
                                                <?php } ?>
                                        </div>
                                    </div>
                                <?php } ?>
                                <?php } ?>
                        <?php
                        endwhile;
                        wp_reset_postdata();
                    endif; ?>
                    </div>
                </div>
            </div>
            <?php }
    }

endif;



if (!function_exists('always_footer_logo_section')):

    function always_footer_logo_section()
    {
        $footer_logo_upload = esc_url(get_theme_mod('footer_logo_upload'));
            if (!empty($footer_logo_upload)) { ?>
                <div class="theme-footer-logo">
                    <a href="<?php echo esc_url(get_site_url());?>">
                        <img src="<?php echo esc_url($footer_logo_upload);?>">
                    </a>
                </div>
            <?php } ?>
        <?php
    }

endif;

add_action( 'always_footer_content_logo','always_footer_logo_section',12 );



if (!function_exists('always_footer_social_nav')):

    function always_footer_social_nav()
    {
        $always_default = always_get_default_theme_options();
        $ed_footer_social_nav = get_theme_mod('ed_footer_social_nav');

        if (has_nav_menu('always-social-menu') && ($ed_footer_social_nav)) { ?>
            <div id="footer-social-nav" class="theme-social-navigation footer-social-navigation">
                <div class="theme-section-heading section-heading-1">
                    <h2 class="theme-section-title alt-font">
                        <?php esc_html_e('follow us', 'always'); ?>
                    </h2>
                </div>
                <?php
                wp_nav_menu(array(
                    'theme_location' => 'always-social-menu',
                    'link_before' => '<span class="screen-reader-text">',
                    'link_after' => '</span>',
                    'container' => 'div',
                    'container_class' => 'social-menu',
                    'depth' => 1,
                )); ?>
            </div>
        <?php } ?>
        <?php
    }

endif;

add_action( 'always_footer_content_social_nav','always_footer_social_nav',15 );

function always_hex2rgb( $colour,$opacity = 1 ) {

    if ( $colour[0] == '#' ) {
        $colour = substr( $colour, 1 );
    }
    if ( strlen( $colour ) == 6 ) {
        list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] );
    } elseif ( strlen( $colour ) == 3 ) {
        list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] );
    } else {
        return false;
    }
    $r = hexdec( $r );
    $g = hexdec( $g );
    $b = hexdec( $b );
    return 'rgba('.$r.','.$g.','.$b.','.$opacity.')';

}

