<?php

add_action('wp_enqueue_scripts', 'theme_enqueue_styles');

function theme_enqueue_styles() {
    wp_enqueue_style('child-style', get_stylesheet_uri(), array('bootstrap', 'parent-style'));

    wp_enqueue_style('owl.carousel.min', get_stylesheet_directory_uri() . '/css/owl.carousel.min.css');
    //wp_enqueue_style( 'owl.theme.default.min', get_stylesheet_directory_uri() . '/css/owl.theme.default.min.css');
    //wp_enqueue_script( 'jquery-3.3.1.min', get_stylesheet_directory_uri() . '/js/jquery-3.3.1.min.js', array( 'jquery' ) );
    //wp_enqueue_script( 'owl.carousel.min', get_stylesheet_directory_uri() . '/js/owl.carousel.min.js', array( 'jquery' ) );
}

// custom menu
function register_my_menu() {
    register_nav_menu('custom-menu', __('custom menu'));
}

add_action('init', 'register_my_menu');

function brands_listings() {
    $brands = get_terms(array(
        'taxonomy' => 'brand',
        'hide_empty' => false,
        'orderby' => 'name',
        'order' => 'ASC'
    ));
    $barray = array();
    $html = '';
    $html .= '<div class="row">';
    
    foreach ($brands as $bindex => $brand) {
        $term_link = get_term_link($brand->term_id);
      //  echo $bindex;

        if ($bindex == 0) {

            $div_counter = 1;
            $html .= '<div class="col-md-4">';
            $barray[] = substr($brand->name, 0, 1);
            $html .= '<ul><li>';
            $html .= '<h1>' . substr($brand->name, 0, 1) . '</h1>';
        } else {
            if (!in_array(substr($brand->name, 0, 1), $barray)) {
                $barray[] = substr($brand->name, 0, 1);
//                $cou= ceil(count($barray)/3);
                $html .= '</ul>';
                
               
                 $html .= '</div>';
                 $html .= '<div class="col-md-4">';
               
                $html .= '<ul><li>';
                $html .= '<h1>' . substr($brand->name, 0, 1) . '</h1>';
                
                
                $div_counter++;
                
                
            } else {
                $html .= '<li>';
            }
//            if ($bindex == (count($brands) - 1)) {
//                $html .= '</div>';  
//            }
            
               
        }
       
        $html .= '<a href="' . $term_link . '">' . $brand->name . '</a>';
        $html .= '</li>';
        
    }
    $html .= '</div></div>';

    //$html .= '</ul>';

    echo $html;
}

add_shortcode('brandsshow', 'brands_listings');
