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
- Can I set a default featured image for a category?
- Could not insert term into the database
- Weird behaviour when adding terms/term_taxonomies programmatically
- How can I get category ID by category name?
- Randomise results from a category page?
- Adding Custom User Profile data based upon Categories
- Order posts by category name
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Remove word “Category” from WooCommerce product page [closed]
- Output link to category from WP_Query loop of woocommerce products
- Password protect a specific category page/post
- If in category to be inside of a function
- How to exclude posts from a category when using this particular format
- Different excerpt styles per category, but chronological
- Show only one category
- Pagination Not Working on Category.php page
- How to view WordPress’ default category IDs?
- Filter Home Page Posts in Buddypress [closed]
- Broken category pagination
- Color different for the current category
- one category template for multiple categories
- Display posts separated by Category in Author’s page
- How can I define a custom archive for childs of a specific category?
- Category shows only top level child categories
- Page display certain Category Posts
- REST API: Display Category names in JSON?
- List posts in alphabetical order
- Where is the category of a post stored?
- Categories list loop – add separator every 3 categories [closed]
- Add image to each podcast series (or category) in headless WordPress instance [closed]
- wp_list_pages() exclude category
- How to define multi categories posts number
- Get the ID of 10 Latest Pages stored in a WordPress Category
- how to separate categories in loop.php?
- How can i remove the posts category class names from body_class
- Different Category Headers using in_category and elseif
- related articles using shortcodes
- Root category template?
- Getting the Most Recent Posts from Multiple Categories
- Add Date & Author Meta to Category Archive Page
- A dropdown with checklist
- How to store category and tags separatly on wordpress?
- Show Secondary Sidebar on Category pages (archive)
- Get post content intro text on category.php?
- Conditional category query breaking?
- Unable to browser posts in categories
- 3.1 post formats and specific categories/custom taxonomies
- Inline If statement to echo CSS [closed]
- Template category.php with page (no posts)
- how to exclude specific category types (uncategorized) from blog page?
- How to set featured image as background for a specific category?
- Confused about category.php template – not working
- wp_list_categories + widget
- Adding relevant categories to related post
- Code to display category-specific single.php is overriding normal single.php, too
- How can I add a Categories page link to a menu? [closed]
- Way to show content of a post, but if exceeds character limit revert to excerpt?
- get posts from 2 categories. (2 posts)
- Display all subcategories for a product category in woocommerce
- Converting Categories (with ACF fields) to custom taxonomies
- Why does my WordPress index has a category?