<?php
get_header(); 

$mo_tag = get_moments_tag_arr();
$moment_label = ppo_moment_label('moment');
$owner_label = ppo_moment_label('owner');
$user_label = ppo_moment_label('user');
?>

<div class="pix-content allmo-warp">
    <div class="allmo-content">
    <div class="uk-grid-medium" uk-grid>
        <div class="uk-width-1-4">
            <div class="left-nav">
                <?php 

                    foreach($mo_tag as $v){
                        if(check_motag_child($v)){
                            echo '<li><span class="allmo-tags" data="'.$v.'">'.$v.'</span></li>';
                        }
                    }
                
                ?>
            </div>
        </div>
        <div class="uk-width-3-4">
            <div class="right-content" uk-height-viewport>
                <?php 
                    foreach($mo_tag as $v){
                        $terms = get_terms( array(
                            'taxonomy'   => 'moments',
                            'hide_empty' => false,
                            'meta_query' => array(
                                array(
                                    'key' => 'ppo_moments_tag',
                                    'value' => $v,
                                    'compare' => '=',
                                ),
                            )
                        ) );
                        if(is_array($terms) && !empty($terms)){
                            echo '<div class="content-inner">';
                            echo '<div class="mos-title">'.$v.'</div>';
                            echo '<div class="inner-list">';

                        if(is_array($terms) && !empty($terms)){
                            $def = THEME_URL.'/img/modef.png';
                            foreach($terms as $term){
                                $term_id = $term->term_id;
                                $mo_data = get_mo_num_data($term_id);
                                $thum = get_term_meta( $term_id, 'mo_cat_img', true );
                                $thum = $thum ? $thum : $def;
                                $user_id = get_term_meta( $term_id, 'mo_owner', true );
                                $user_id = $user_id ? $user_id : 1;
                                $user_info = get_userdata($user_id);
                                $avatar = get_u_avatar($user_id,'img');
                                $ofi = $user_id == 1 ? '<small>官方</small>' : '';
                                echo '<div class="allmo-tags-item rounded" catid="'.$term_id.'">
                                            <a class="link-cover" href="'.esc_url(get_term_link($term_id, 'moments')).'"></a>
                                            <div class="left"><img src="'.$thum.'" class="cover-img rounded"></div>
                                            <div class="right">
                                                <div class="title">'.$term->name.'</div>
                                                <div class="circle-owner">'.$avatar.''.$user_info->display_name.'('.esc_html($owner_label).')</div>
                                            </div>
                                            <div class="bottom">
                                                <div class="count-mo">'.$term->count.esc_html($moment_label).' <span>·</span> '.$mo_data['join'].esc_html($user_label).'</div>
                                                <div class="info">'.$ofi.'</div>
                                            </div>
                                            </div>';
                            }
                        }

                            echo '</div></div>';
                        }
                    }
                ?>
            </div>
        </div>
    </div>
        
    </div>
</div>

<?php
get_footer();  
