Skip to content

Commit

Permalink
Add fallback for empty dashboard if everything is in trash
Browse files Browse the repository at this point in the history
  • Loading branch information
hofmannsven committed May 21, 2014
1 parent c8c2252 commit 4a4b520
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions admin/views/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


/**
* Get marker
* Get marker terms
*
* @since 1.0.0
*/
Expand All @@ -25,29 +25,33 @@
);
$markers = get_terms( 'marker', $marker_args );

/**
* Get all markers but trashed
*
* @since 1.0.7
*/
global $wpdb;
$marker_items = '';
if ( ! empty( $markers ) ) :
foreach ( $markers as $marker ) :
$trashed = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $marker->term_id AND p.post_status = 'trash' LIMIT 1" );
$count = $marker->count - $trashed;
if ( $count > 0 ) :
$marker_items .= '<li class="mark-posts-info mark-posts-' . $marker->slug . '"><span>' . $count . ' ' . $marker->name . '</span></li>';
endif;
endforeach;
endif;

?>

<div class="main">
<ul id="markers_right_now">
<?php
if ( ! empty( $markers ) ) :
foreach ( $markers as $marker ) :
/**
* Get trashed marker and remove them from total count
*
* @since 1.0.7
*/
global $wpdb;
$trashed= $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts p JOIN $wpdb->term_relationships rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = $marker->term_id AND p.post_status = 'trash' LIMIT 1");
$count = $marker->count - $trashed;
if ( $count > 0 ) :
echo '<li class="mark-posts-info mark-posts-' . $marker->slug . '"><span>' . $count . ' ' . $marker->name . '</span></li>';
endif;
endforeach;
else:
if ( ! empty( $marker_items ) ) :
echo $marker_items;
else :
_e( 'No marked posts yet.', 'mark-posts' );
endif;
?>
</ul>
<!-- /#markers_right_now -->
</ul><!-- /#markers_right_now -->
</div><!-- /.main -->

0 comments on commit 4a4b520

Please sign in to comment.