Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create custom post and custom texonomy for categories; here custom post name gallery and cutom-texonomy name gallery-cat;
- <div class="row">
- <!-- Nav tabs -->
- <ul class="nav nav-tabs" role="tablist">
- <?php
- $gallery_terms = get_categories( array(
- 'taxonomy' => 'gallery-cat',
- 'hide_empty' => false,
- ) );
- $all_gallery_post = array();
- $all_gallery_post_by_category = array();
- $is_active = true;
- foreach ($gallery_terms as $term_object):
- $post_object_arr_by_category_id = get_posts(
- array(
- 'showposts' => 6,
- 'post_type' => 'gallery',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'gallery-cat',
- 'field' => 'term_id',
- 'terms' => $term_object->term_id
- )
- )
- )
- );
- $all_gallery_post = array_merge($all_gallery_post, $post_object_arr_by_category_id);
- $all_gallery_post_by_category[$term_object->slug] = $post_object_arr_by_category_id;
- ?>
- <li role="presentation" class="<?php echo ( $is_active ) ? 'active' : ''; ?>">
- <a href="#gallery-<?php echo $term_object->slug; ?>" role="tab" data-toggle="tab"><?php echo $term_object->name; ?></a>
- </li>
- <?php $is_active = false; endforeach; ?>
- </ul>
- <!-- Tab panes -->
- <div class="tab-content">
- <?php foreach ($all_gallery_post_by_category as $gallery_slug => $post_object_arr): ?>
- <div role="tabpanel" class="tab-pane <?php echo ( ! $is_active ) ? 'active' : ''; ?>" id="gallery-<?php echo $gallery_slug; ?>">
- <?php foreach ($post_object_arr as $post_object): ?>
- <div class="col-sm-4 col-xs-6 col-xxs-12">
- <div class="ic-single-g-item">
- <?php echo get_the_post_thumbnail($post_object->ID, 'gallery-img'); ?>
- <div class="ic-title-n-cat">
- <h3><?php echo $post_object->post_title; ?></h3>
- <!-- <span><?php //echo get_post_meta(get_the_ID(), 'gallery_sub_t', true); ?></span> -->
- </div>
- </div>
- </div>
- <?php endforeach; ?>
- </div>
- <?php $is_active = true; endforeach; ?>
- </div>
- </div>
- //Custom post
- register_post_type( 'gallery',
- array(
- 'labels' => array(
- 'name' => __( 'Gallery' ),
- 'singular_name' => __( 'gallery' ),
- 'add_new_item' => __( 'Add new gallery item' )
- ),
- 'public' => true,
- 'rewrite' => array( 'slug' => 'galleries' ),
- 'menu_position' => 5,
- 'supports' => array( 'title', '', 'thumbnail'),
- 'has_archive' => true,
- )
- );
- //Custom texonomy
- register_taxonomy(
- 'gallery-cat', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'gallery', //post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Gallery Category', //Display name
- 'query_var' => true,
- 'show_admin_column' => true,
- 'rewrite' => array(
- 'slug' => 'gallery-category', // This controls the base slug that will display before each term
- 'with_front' => true // Don't display the category base before
- )
- )
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement