wordpress条件语句

wordpress条件语句,wordpress,widget,parent-child,conditional-statements,Wordpress,Widget,Parent Child,Conditional Statements,我正试图在WordPress小部件逻辑中使用此逻辑: 小部件显示它是否不是主页或第86页,或者它是否是第86页的子项 !is_home || !is_page('86') || !is_child('86') 我已将此函数添加到functions.php中: function is_child($parent) { global $post; return $post->post_parent == $parent; } 试试这个: (!is_home() &&am

我正试图在WordPress小部件逻辑中使用此逻辑: 小部件显示它是否不是主页或第86页,或者它是否是第86页的子项

!is_home ||  !is_page('86') ||  !is_child('86')
我已将此函数添加到functions.php中:

function is_child($parent) {
  global $post;
  return $post->post_parent == $parent;
}
试试这个:

(!is_home() && !is_page(86) &&  !is_child(86))
is_home()
是一个函数。为了检查页面,我建议使用整数而不是字符串。 而整个
()
只是一个安全措施。也许你可以把他们排除在外,我不确定。
未测试。

谢谢janw的回复。但是,小部件仍然会打印到所有页面该函数是否更合适:
函数是_-tree($pid){//$pid=我们在全局$post下查找的页面的ID;//如果(是_-page($pid))加载有关此页面的详细信息return true;//我们在页面或子页面$anc=get_post_祖先($post->ID);foreach($anc as$祖先){if(is_page()&&&$祖先==$pid){return true;}}}返回false;//我们不在页面,页面不是祖先}
如果删除is\u子项,这是否有效?同时启用WP_DEBUG以检查错误。也许你不能在这里使用
is_child
我使用的第二个函数:'!你在家吗!是第(86)页!is_tree('86')顺便说一句,我也尝试过使用重置查询,但运气不好:
wp_reset_query()