I'm not good at wordpress coding. but i want to display a widget on specific category with its sub categories and all child posts.

Is there any simple way for this purpose ?

I found out the "Widget Logic" plugin on this link : https://wordpress.org/plugins/widget-logic/

This plugin do exactly what i want.

1 Answer 1


you can test category identifier and parent in a widget with that :

class WidgetExample extends \WP_Widget

    public const IDENTIFIANT = "example1";
    public const CATEGORY_ID = 25;

    public function __construct()
            , "Example"

    public function widget($args, $instance)

        if (!is_category()) {

        $currentCategory = get_queried_object();

        if (    (self::CATEGORY_ID !== $currentCategory->ID)
            &&  (self::CATEGORY_ID !== $currentCategory->parent)
        ) {

        echo "We are on category " . self::CATEGORY_ID;


    public function form($instance) {

  • Thanks but i can't underestand the code. I'm using a commercial theme , and i want to display an Ad on specific category with all subcategories and all posts on those categories. but i'm not a i'm not a programmer. Aug 7, 2018 at 10:44
  • I found out the "Widget Logic" plugin on this link : wordpress.org/plugins/widget-logic This plugin do exactly what i want. Aug 8, 2018 at 13:42

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.