使用 Wordpress 中的 Widget Logic 插件在特定页面中显示小部件
Show widget in specific pages with Widget Logic plugin in Wordpress
我试图在 Wordpress 中使用 Widget Logic 插件仅在特定页面中显示小部件,但我无法使其在两种(Line2 和 Line3)情况下都有效。如果我尝试代码的每个部分都运行良好。
$cats = array('test1','test2','test3');
global $post; return (in_array(1317, get_post_ancestors($post))) || is_tax('categories', $cats);
global $post; return is_single() && has_term($cats, 'categories', $post->ID);
好的,我添加了一个 if,现在在两种情况下都可以正常工作...
$cats = array('test1','test2','test3');
global $post;
if ((in_array(1317, get_post_ancestors($post)))) || is_tax('categories', $cats)) {
return true;
}
elseif (is_single() && has_term($cats, 'categories', $post->ID)) {
return true;
}
else return false;
我试图在 Wordpress 中使用 Widget Logic 插件仅在特定页面中显示小部件,但我无法使其在两种(Line2 和 Line3)情况下都有效。如果我尝试代码的每个部分都运行良好。
$cats = array('test1','test2','test3');
global $post; return (in_array(1317, get_post_ancestors($post))) || is_tax('categories', $cats);
global $post; return is_single() && has_term($cats, 'categories', $post->ID);
好的,我添加了一个 if,现在在两种情况下都可以正常工作...
$cats = array('test1','test2','test3');
global $post;
if ((in_array(1317, get_post_ancestors($post)))) || is_tax('categories', $cats)) {
return true;
}
elseif (is_single() && has_term($cats, 'categories', $post->ID)) {
return true;
}
else return false;