• Charliebee1990

    (@charliebee1990)


    I am using the blankslate template and would like to hide a category in my list in the sidebar.

    I know you can hide it like this: <?php wp_list_categories('exclude=8,8&title_li=') ?>

    But i am confused how to integrate this into my widget sidebar as i have other widgets.

    I hope this makes sense and any guidance would be great!

    In this form the sidebar is displayed like this:

    sidebar.php

    <?php if ( is_active_sidebar('primary-widget-area') ) : ?>
    	<div id="primary" class="widget-area">
    		<ul class="sid">
            	<?php dynamic_sidebar('primary-widget-area'); ?>
        	</ul>
    	</div>
    <?php endif; ?>

    and the function for this is in the functions file: (here is a snippet of it)

    functions.php

    function blankslate_widgets_init() {
    register_sidebar( array (
    'name' => __('Sidebar Widget Area', 'blankslate'),
    'id' => 'primary-widget-area',
    'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
    'after_widget' => "</li>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>'
    ) );
    }
    $preset_widgets = array (
    'primary-aside'  => array( 'search', 'pages', 'categories', 'archives' ),
    );
    function blankslate_get_page_number() {
    if (get_query_var('paged')) {
    print ' | ' . __( 'Page ' , 'blankslate') . get_query_var('paged');
    }
    }
    function blankslate_catz($glue) {
    
    $current_cat = single_cat_title( '', false );
    $separator = "\n";
    $cats = explode( $separator, get_the_category_list($separator) );
    foreach ( $cats as $i => $str ) {
    if ( strstr( $str, ">$current_cat<" ) ) {
    unset($cats[$i]);
    break;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • tidythemes

    (@tidythemes)

    Instead of going through all that trouble, why not simply create a custom menu under Appearance > Menus with only the category links you want and then under Appearance > Widgets, assign it to a Custom Menu widget.

    Also, feel free to use the official forum in the future:

    https://tidythemes.com/forum/

    Thanks

    Thread Starter Charliebee1990

    (@charliebee1990)

    Hi there,

    This is my very first attempt at using WordPress so i’m sorry i didn’t realize you could do that. Your reply was the most simple thing to do! I will take a look into this forum as well.

    Thanks

    tidythemes

    (@tidythemes)

    Sure thing, there’s always 10 different ways to do something, and there has to be an easiest :).

    Michael

    (@alchymyth)

    there is also the way of using a filter function to influence the widget parameters;

    add_filter('widget_categories_args','set_category_widget_parameters');
    function set_category_widget_parameters($args) {
    $args['exclude'] = '8';
    return $args;
    }

    the code needs to be added into functions.php of the theme.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide a category in sidebar’ is closed to new replies.