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()
{
parent::__construct(
self::IDENTIFIANT
, "Example"
);
}
public function widget($args, $instance)
{
if (!is_category()) {
return;
}
$currentCategory = get_queried_object();
if ( (self::CATEGORY_ID !== $currentCategory->ID)
&& (self::CATEGORY_ID !== $currentCategory->parent)
) {
return;
}
echo "We are on category " . self::CATEGORY_ID;
}
public function form($instance) {
}
}
Related Posts:
- Using wp_category_checklist in a widget
- How to remove the parentheses from the category widget
- How to create a widgetized sidebar for every category dynamically?
- Customizing Default Categories Widget
- Display all posts with same title
- I want to create a posts widget and be able to select categories
- How to have Multiple Archives Widgets, one archive widget per category (in a different page)?
- Categories lose hierarchy order once assigned to post
- Add Icons to the Product Category Sidebar Widget WooCommerce
- How to display widgets inside a page content without a plugin?
- How do you categorize pages?
- WordPress category widget only show categories with children
- Customize WordPress widget – Product Category
- Post Count for Categories, however not to calculate a total
- How do I make the category sidebar widget (stock) display the total # of posts including those in subcategories?
- Categories widget show empty?
- Is it possible to remove from default category widget?
- how to remove the default title of Categories widget
- How to show 5 posts from specific category on related page?
- Multiple selection for wordpress widget
- How to not display subcategories in Recent Posts widget area?
- How to Sync Menu, Widgets and other masters from Main Website to its Sub Site
- Tags Instead of Category
- How to hide widget from certain category
- Last x Posted Categories?
- WordPress category filters as subcategories
- exclude certain categories form archive widget
- Conditional widget for theme template file
- Add filter for specific category only
- Exclude a category from block editor’s category widget
- How can I display the category name in the single post when using WP Blog and Widget?
- How to Change Sort Order of default WordPress Catgory Widgets?
- How to add an “All” category to the tag cloud?
- Custom file with special code of category widget
- in_category(‘category-sluga’) returns true for Archive page of Category ‘category-slugb’
- Problem with single posts not showing correct category sidebar
- How To Disable Category Hierarchy In Categories Widget?
- single category widget with conditional terms
- Customize category query in widget
- WP REST API: filter by category 1 AND category 2
- Display All Products by Category with WooCommerce
- Get only the top level categories using get_categories() without foreach loop
- get_terms vs. get_categories: does it matter?
- What is a good robots.txt?
- Add a URL prefix to permalinks of one category of posts only
- Woocommerce get category image full size
- Remove / Rename Uncategorized Category In WordPress
- Fixing category count
- Can a Child Category Have More than One Parent?
- Rewrite URL with category and tag combined using WP_Rewrite
- Add forward slash on categories url (serve one version of a url)
- How to get the category of the post and link it to the archive (of the category)
- Woocommerce Product Category Widget – hide categories that have no products in stock [closed]
- Alphabetical Index Page
- How to display Last Updated date from the latest post for a category list
- adding custom fields to next and previous post link
- Categories Listing with “selected” category highlighted
- Exclude Category From Home Page, Display Posts on It’s Own Page?
- Update term count using a callback function
- Assign parent category to all posts that are already assigned to child category
- Page navigation within a category
- Category Descriptions – HTML?
- How to have a static category/author page?
- Can the_category display a post count?
- Related content based on category name
- If no posts in category display Form instead of not found
- Permalinks – Different structures for different categories?
- How can i call an article from each category and still paginate properly?
- programmatically adding categories to custom taxonomy
- Getting WordPress custom taxonomy/category?
- Return category slug / title from category ID
- How to Import Categories with Descriptions from a CSV File?
- Modification to wp_list_categories
- How to run WP_Query to retrieve attachments to posts only from a particular category?
- Migrate posts into a different category
- WordPress Multisite – global categories
- How to get child categories of a given Post
- Display “add to cart” button on every listing in product category page?
- How to get post category title within the loop?
- If category is in parent category?
- Hide posts of a certain category unless logged in
- How to filter posts by format and category via url?
- WP_Query() returns null when results exist!
- Woocommerce category show subcategories only/omit posts for specific category
- shop page with all categories with paginate
- Get Tags specific to Category using WooCommerce plugin
- Giving wp_list_categories the class of the category
- How to filter out Categories for specific post types on WordPress Admin?
- Limit a meta box to a specific category
- get_posts and multiple categories
- List categories with posts
- Pagination not visible on woocommerce’s category page
- Category archive rewrite rule to include category/subcategory?
- How can I automatically display a visual archive of subcategory posts [and thumbnails] separate from Parent category?
- The default code for “posts_nav_link” on category.php isn’t working
- Only one post is showing on category page, why?
- Woocommerce custom category pages
- Custom sub taxonomy order by
- Hide uncategorized when no category set
- wp_list_categories set order manually?