Created
February 17, 2015 02:25
-
-
Save Aziz-Rahman/c82c969edabf4274a46c to your computer and use it in GitHub Desktop.
Shortcodes untuk menampilkan CATEGORY ARTICLE dengan CATEGORY-nya masing2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shortcodes Article Category | |
* Untuk menampilkan semua category article dengan categorynya masing2 (di dlm tiap2 category article ada categorynya masing2) | |
* @package WordPress | |
* @subpackage Lat | |
* @since Lat 1.0.0 | |
*/ | |
//shortcodes Category | |
function category( $atts ) { | |
extract( shortcode_atts( | |
array( | |
'title' => '', | |
'limit' => '' | |
), $atts ) ); | |
?> | |
<div class="container"> <!-- Container out --> | |
<div id="leftcontent" class="full-width"> | |
<div class="home-top widget warrior_recent_posts_by_category"> | |
<div class="homepage-categories"> | |
<div class="container"> | |
<?php echo '<h2 class="widget-title">'.$title.'</h2>'; ?> | |
<div class="row row-2"> | |
<?php | |
// Select taxonmony | |
$taxonomies = array( | |
'kb_category', | |
); | |
// Filter taxonomy | |
$args = array( | |
'hide_empty' => false, | |
); | |
// Get taxonomy data | |
$terms = get_terms( $taxonomies, $args ); | |
// Loop each taxonomy | |
foreach( $terms as $catsid ) : | |
if( $catsid ) : | |
$args = array( | |
'type' => 'post', | |
'hide_empty' => 0, | |
'hierarchical' => 0, | |
'taxonomy' => 'kb_category', | |
'pad_counts' => false | |
); | |
$mycats = get_categories( $args ); | |
$taxonomy = 'kb_category'; | |
$term = get_term( $catsid, $taxonomy ); | |
$term_name = $term->name; | |
$term_slug = $term->slug; | |
$term_count = $term->count; | |
?> | |
<div class="column"> | |
<div class="block article-list"> | |
<h4 class="widget-title"> <i class="typcn typcn-folder"></i> | |
<?php echo $term_name; ?><span class="article-count"><?php echo $term_count; ?> <?php _e('articles', 'lat'); ?></span> | |
</h4> | |
<?php | |
$args = array( | |
'post_type' => 'knowledge_base', | |
'taxonomy' => 'kb_category', | |
'term' => $term_slug, | |
'posts_per_page'=> $limit, | |
'post_status' => 'publish' | |
); | |
?> | |
<ul> | |
<?php | |
$wp_query = new WP_Query(); | |
$wp_query->query( $args ); | |
if( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); | |
?> | |
<li id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | |
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> | |
<?php the_title(); ?> | |
</a> | |
</li> | |
<?php endwhile; else: ?> | |
<?php _e('There\'s no post in this category.', 'lat'); ?> | |
<?php endif; ?> | |
</ul> | |
</div> | |
</div> <!-- END: class column--> | |
<?php endif; ?> | |
<?php endforeach; ?> <!--END: Loop each taxonomy --> | |
</div> | |
</div> | |
</div><!-- END: class homepage-categories--> | |
</div> | |
</div> | |
</div><!-- END: Container out --> | |
<?php | |
} | |
add_shortcode( 'article_category', 'category' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment