Created
May 17, 2018 15:57
-
-
Save nfsarmento/c0ea6a4f82169f20c6219987c2c6feca to your computer and use it in GitHub Desktop.
WordPress Custom Post Type Categories - Collapse List
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
$('.toggle__categories').click(function(e) { | |
e.preventDefault(); | |
var $this = $(this); | |
$this.next().toggleClass(); | |
$this.next().slideToggle(); | |
}); | |
$(function() { | |
$('.plus-minus-toggle').on('click', function() { | |
$(this).toggleClass('collapsed'); | |
}); | |
}); |
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
<div class="col-sm-2 categories__list"> | |
<div class="divider__top"></div> | |
<?php $cat_args = array ( | |
"orderby" => "date", | |
'order' => 'DESC', | |
'taxonomy' => 'monthly_categories', | |
); | |
$categories = get_categories ( $cat_args ); | |
foreach ( $categories as $category ) { | |
$cat_query = null; | |
$args = array ( | |
'posts_per_page' => -1, | |
'post_type' => 'monthly_updates', | |
'taxonomy' => 'monthly_categories', | |
'term' => $category->slug | |
); | |
$cat_query = new WP_Query( $args ); | |
if ( $cat_query->have_posts() ) { | |
?> | |
<h5 class="ttoggle__categories plus-minus-toggle collapsed"><?php echo $category->name; ?></h5> | |
<ul class="inner" style="display:none;"> | |
<?php while ( $cat_query->have_posts() ) { | |
$cat_query->the_post(); ?> | |
<li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> | |
<?php } ?> | |
</ul> | |
<div class="divider__bottom"> | |
</div> | |
<?php } wp_reset_postdata(); } ?> | |
</div> |
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
.divider__top{ | |
border-top: 5px solid #29abe3; | |
} | |
.divider__bottom{ | |
border-bottom: 2px solid #99deff; | |
} | |
.categories__list ul { | |
list-style: none; | |
padding: 0; | |
} | |
h5.toggle__categories { | |
font-weight: bold; | |
} | |
.plus-minus-toggle { | |
cursor: pointer; | |
height: 21px; | |
position: relative; | |
width: 100%; | |
} | |
.plus-minus-toggle:before, | |
.plus-minus-toggle:after { | |
background: #000; | |
content: ''; | |
height: 2px; | |
right: 2px; | |
position: absolute; | |
top: 7px; | |
width: 9px; | |
transition: transform 500ms ease; | |
} | |
.plus-minus-toggle:after { | |
transform-origin: center; | |
} | |
.plus-minus-toggle.collapsed:after { | |
transform: rotate(90deg); | |
} | |
.plus-minus-toggle.collapsed:before { | |
transform: rotate(180deg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment