0

I need tag archives don't display specific categories. Thanks!

1
  • 1
    Welcome to WPSE. What have you tried? What have you researched? We do expect that you to have at least tried something. Please file an edit with your research effort and the code you have written, working or not, and explain where you are stuck. Thank you :-) Feb 9, 2015 at 5:02

1 Answer 1

0

One way to do this would be to create a custom widget which displays categories using wp_list_categories(). Then exclude any categories you don't want displayed using the exclude option of wp_list_categories(): http://codex.wordpress.org/Template_Tags/wp_list_categories#Include_or_Exclude_Categories.

This example below creates a custom categories widget in Appearance / Widgets. This code can be added to functions.php or used in a plugin.

/*-----------------------------------------------------------------------------------*/
/* Create category list widget */
/*-----------------------------------------------------------------------------------*/
class ABCD_Category_Widget extends WP_Widget
{
  function ABCD_Category_Widget()
  {
    $options = array( 'classname' => 'ABCD_Category_Widget', 'description' => 'Displays a list of categories' );
    $this->WP_Widget( 'ABCD_Category_Widget', 'ABCD Category List', $options );
  }

  function form( $instance )
  {
    $instance = wp_parse_args( ( array ) $instance, array( 'title' => '' ) );
    $title = $instance['title'];
  ?>
  <p><label for="<?php echo $this->get_field_id( 'title' ); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo attribute_escape( $title ); ?>" /></label></p>
  <?php
  }

  function update( $new_instance, $old_instance )
  {
    $instance = $old_instance;
    $instance['title'] = $new_instance['title'];
    return $instance;
  }

  function widget( $args, $instance )
  {
    extract( $args, EXTR_SKIP );

    echo $before_widget;
    $title = empty( $instance['title'] ) ? ' ' : apply_filters( 'widget_title', $instance['title'] );

    if ( !empty( $title ) )
      echo $before_title . $title . $after_title;

    $args = array(
    'orderby'       => 'name', 
    'order'         => 'ASC', 
    'number'        => null,
    'optioncount'   => true, 
    'exclude_admin' => true, 
    'show_fullname' => false,
    'hide_empty'    => true,
    'echo'          => true,
    'style'         => 'list',
    'exclude'       => array( 20, 26 ), // IDs of categories you want to exclude
    'title_li'      => __( '' ),
    'html'          => true
    );


    echo '<ul>', wp_list_categories( $args ), '</ul>';

    echo $after_widget;
  }

}
add_action( 'widgets_init', create_function( '', 'return register_widget("ABCD_Category_Widget");' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.