我需要运行一个函数(显示模态)如果一个页面DOES有一个特定的字段值和不是某个页面。如果页面没有字段值并且它不是特定的页面,它也需要工作。它们分别是这样工作的:
//如果page有字段值:
<?php
$values = get_field( 'recast_video' );
if ( ($values) ) {
get_template_part('template-parts/popIn', 'none');
}
?>
//if it is this page, do not show:
<?php
if ( (!is_page('trading-education-webinars') ) ){
get_template_part('template-parts/popIn', 'none');
}
?>
我如何结合两者,使它显示(get_template_part)如果字段具有值和不是指定的页面
//this fails
<?php
$values = get_field( 'recast_video' );
if ( ($values) || (!is_page('trading-education-webinars') ) ){
get_template_part('template-parts/popIn', 'none');
}
?>
首先要做的是查找常见情况。无论如何,你都不希望它是某一页,对吧?首先检查是不是那个页面:
$result = (!is_page('trading-education-webinars')) ? : ;
它也需要工作,如果页没有字段值和它不是某一页
那么为什么要检查字段值呢?没有必要,只要它不是我们检查的页面。
$result = (!is_page('trading-education-webinars')) ? get_template_part('template-parts/popIn', 'none') : return false;
如果页面是"交易-教育-网络研讨会",您可以将return false;
更改为任何您想要发生的事情
编辑:澄清条件:
- Page X永远不会得到"content" (modal)
- 如果不是X页并且有$值,显示内容
- 如果NOT页X和NOT有$值,显示一些其他内容
$values = get_field('recast_video');
$x = get_template_part('template-parts/popIn', 'none');
$y = 'some other content';
$return = (!is_page('trading-education-webinars')) ? (($values) ? $x; : $y ) : return false );
使用&&(和)操作符:
<?php
$values = get_field( 'recast_video' );
if ( ($values && !is_page('trading-education-webinars')) || (!$values && is_page('trading-education-webinars')) ){
get_template_part('template-parts/popIn', 'none');
}
?>
||当至少一个或两个语句为真时