IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. CMS
  4. Wordpress
  5. Controling Category List on Sidebar Widget

Controling Category List on Sidebar Widget

2021-03-04 3368 Views 1 Like 2 Comments

Category list on sidebar widget will display all categories on post category hierarchy by default. However, we do not want to display all of them for some reason. Here is simple technique to achieve this goal.

Controling Category List on Sidebar Widget

Table of Contents

  • Find category IDs
  • Snippets
  • Apply the snippets

Find category IDs

First thing to do is to find out all category IDs that we don't want them to show on the sidebar. Run the following script against WordPress MySQL database.

SELECT t.term_id catID,t.name FROM wp_terms t
join wp_term_taxonomy tax on tax.term_id=t.term_id
where tax.taxonomy='category'

Controling Category List on Sidebar Widget

Snippets

//Hide categories from WordPress category widget
function exclude_widget_categories($args){
    $exclude = "4,6,7,8,9,10,13,14,15,16";
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");

Apply the snippets

There are many ways to apply the snippets. You could add it to theme functions.php file or using snippets plugin to apply the snippets code. In my case, I'm using snippets to apply the code. This way is better organized for reusing the snippets.

Last words, This is the simplest way to contorl the category list on sidebar, but you may use other ways to control the category list on sidebar, for instance, find a proper plugin or write your own plugin to achieve it.

 9,600 total views,  2 views today

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: Blog
Last updated:2021-03-04

IT Team

This person is lazy and left nothing

Like
< Previous
Next >

Comments

  • Lilia

    What’s up, I wish for to subscribe for this blog to take most
    recent updates, so where cann i do it please
    help out.

    2021-03-18
    Reply
    • IT Team

      @Lilia To keep posted, please register here: https://blog.hostlike.com/register/

      2021-03-18
      Reply
  • Cancel reply
    Chinese (Simplified) Chinese (Simplified) Chinese (Traditional) Chinese (Traditional) English English French French German German Japanese Japanese Korean Korean Russian Russian
    Newest Hotspots Random
    Newest Hotspots Random
    Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
    New team member have no permission to access - Dynamics 365 Feature points sampling method validating reports Mixed Content warning: request an insecure element was automatically upgraded to HTTPS Restrict WordPress user access some contents Setting Up Mail for [Contact Form 7] concat all columns in SQL Server
    Categories
    • Architecture
    • BI
    • C#
    • CSS
    • Database
    • DotNET
    • Hosting
    • HTML
    • JavaScript
    • PHP
    • Program Language
    • Python
    • Security
    • SEO
    • Technology
    • Web
    • Wordpress

    COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

    This site is supported by Hostlike.com