admin管理员组文章数量:1332881
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 : /
This plugin do exactly what i want.
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/plugins/widget-logic/
This plugin do exactly what i want.
Share Improve this question edited Aug 8, 2018 at 13:43 Milad asked Aug 6, 2018 at 19:54 MiladMilad 13 bronze badges1 Answer
Reset to default 1you 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) {
}
}
本文标签: display a widget on specific category and its sub categories
版权声明:本文标题:display a widget on specific category and its sub categories 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315938a2451816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论