Add post type tab filters

This commit is contained in:
Takumi
2013-07-27 19:28:17 +10:00
parent 7c9db97814
commit 7c9d55cd93
3 changed files with 27 additions and 8 deletions

View File

@@ -39,25 +39,27 @@ function sp_event_team_meta( $post ) {
for ( $i = 0; $i < $limit; $i++ ):
?>
<div>
<p>
<p class="sp-tab-select">
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sportspress[sp_team][]',
'class' => 'sportspress-pages',
'show_option_none' => __( 'None' ),
'option_none_value' => 0,
'selected' => $teams[ $i ]
);
wp_dropdown_pages( $args );
?>
<input name="sportspress[sp_score][]" type="text" placeholder="<?php _e( 'Score', 'sportspress' ); ?>" size="4" value="<?php echo $scores[ $i ]; ?>" />
</p>
<ul id="sportspress-tabs" class="wp-tab-bar">
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
<li class="wp-tab-active"><a href="#sp_player-all"><?php _e( 'Players', 'sportspress' ); ?></a></li>
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
</ul>
<?php
sp_post_checklist( $post->ID, 'sp_player', false );
sp_post_checklist( $post->ID, 'sp_staff', $i == $limit - 1, 'none' );
sp_post_checklist( $post->ID, 'sp_player', false, 'block', 'sp_team' );
sp_post_checklist( $post->ID, 'sp_staff', $i == $limit - 1, 'none', 'sp_team' );
?>
</div>
<?php

View File

@@ -112,12 +112,12 @@ if ( ! function_exists( 'sp_team_logo' ) ) {
}
if ( ! function_exists( 'sp_post_checklist' ) ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $add_new_item = true, $display = 'block' ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $add_new_item = true, $display = 'block', $data = null ) {
if ( ! isset( $post_id ) )
global $post_id;
$obj = get_post_type_object( $meta );
?>
<div id="<?php echo $meta; ?>-all" class="wp-tab-panel sp-tab-panel" style="display: <?php echo $display; ?>;">
<div id="<?php echo $meta; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel" style="display: <?php echo $display; ?>;">
<input type="hidden" value="0" name="sportspress[<?php echo $meta; ?>]" />
<ul class="categorychecklist form-no-clear">
<?php
@@ -127,8 +127,17 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
foreach ( $posts as $post ):
$parents = get_post_ancestors( $post );
if ( $data )
$data_values = (array)get_post_meta( $post->ID, $data, false )
?>
<li>
<li class="sp-post<?php
if ( $data ):
echo ' sp-filter-0';
foreach ( $data_values as $data_value ):
echo ' sp-filter-' . $data_value;
endforeach;
endif;
?>">
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
<label class="selectit">
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>][]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>

View File

@@ -1,6 +1,14 @@
jQuery(document).ready(function($){
$('.sp-tab-panel').siblings('.wp-tab-bar').find('a').click(function() {
// Switch tabs
$('.sp-tab-panel').siblings('.sp-tab-bar').find('a').click(function() {
$(this).closest('li').removeClass('wp-tab').addClass('wp-tab-active').siblings().removeClass('wp-tab-active').addClass('wp-tab').closest('.wp-tab-bar').siblings($(this).attr('href')).show().siblings('.wp-tab-panel').hide();
return false;
});
// Filter tabs
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() {
$(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide().filter('.sp-filter-'+$(this).val()).show();
return;
});
// Activate tab filters
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
});