getdave / Tanlinell

Boilerplate Wordpress theme for rapid development of new WP themes. Based on the great work of the _s ("Underscore") theme.
GNU General Public License v2.0
6 stars 2 forks source link

Inconsistent Sidebars #330

Closed getdave closed 10 years ago

getdave commented 10 years ago

Currently there are too many sidebars appearing in projects. Specifically I've noticed:

  1. Creation of multiple sidebars for each CPT. Needs to be standardised into a single reusable file.
  2. Failure to utilise standard WP function wp_list_pages() which auto-handles the "active" classes...etc
  3. Inconsistent and overly-opinionated markup patterns

Can we standardise our sidebars to

  1. All use standard base markup
  2. All make use of wp_list_pages
  3. Have dedicated pre-built sidebars for CPTs, Page Descendants, Archoves, Categories and any other variations you can think of.

An example markup is below...

<?php
/**
 * CPT Sub Navigation
 */

$pt_obj = get_post_type_object( get_post_type() );

//requires cpt to be defined as 'hierarchical' => true
$args = array(
    'post_type'=>$pt_obj->name,
    'sort_column'  => 'menu_order, post_title',
    'sort_order'   => 'ASC',
    'title_li'=> false,
    'echo'=>0
);
$list_pages      = wp_list_pages( $args );

$section_title = $pt_obj->labels->name;

?>

<?php if( $list_pages ) : ?>
    <aside class="sidebar sidebar--nav-<?php echo $pt_obj->name; ?>">
        <h5 class="h4"><?php echo ucwords(esc_html($section_title)); ?></h5>
        <ul class="block-list block-list--dashed">
            <?php echo $list_pages; ?>
        </ul>
    </aside>
<?php endif; ?>