<?php
/**
 * Template For Header Category
 * @since 1.0
 * @package RoyalNews
 */

 $cats = get_categories(array(
    'hide_empty' => true,
    'number' => royalnews_value( 'number-of-cat' )
 ));
 if( $cats ){?>
    <div class="royalnews-header-cat-wrap">
        <div class="container">
            <div class="royalnews-header-cat">
                <?php $title = royalnews_value( 'categoty-title-text' );
                if( '' != $title ){ ?>
                    <h3 class="royalnews-category-title"><?php echo esc_html( $title ); ?></h3>
                <?php }
                foreach( $cats as $cat ){ 
                    $image_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
                    $cat_img = wp_get_attachment_image_src( $image_id, 'thumbnail' ); ?>
                    <div class="royalnews-header-cat-inner">
                        <a href="<?php echo esc_url( get_term_link( $cat ) ) ?>">
                            <?php if( '' != $cat_img ){ ?>
                                <img src="<?php echo esc_url( $cat_img ) ?>">
                            <?php } ?>
                            <p><?php echo esc_html( $cat->name ); ?></p>
                        </a>
                    </div>
                <?php } ?>
            </div>
        </div>
    </div>
<?php }?>
 