php函数的真与假条件
我有一个php函数,我正试图将它与真和假条件一起使用php函数的真与假条件,php,function,Php,Function,我有一个php函数,我正试图将它与真和假条件一起使用 function tribe_is_past_event( $event = null ) { if ( is_null( $event ) ) { global $post; $event = $post; } // Check if event has passed $gmt_offset = ( get_option( 'g
function tribe_is_past_event( $event = null ) {
if ( is_null( $event ) ) {
global $post;
$event = $post;
}
// Check if event has passed
$gmt_offset = ( get_option( 'gmt_offset' ) >= '0' ) ? ' +' . get_option( 'gmt_offset' ) : ' ' . get_option( 'gmt_offset' );
$gmt_offset = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $gmt_offset );
if ( strtotime( tribe_get_end_date( $event, false, 'Y-m-d G:i' ) . $gmt_offset ) <= time() ) {
return true;
}
return false;
}
函数是过去的事件($event=null){
如果(为空($event)){
全球$员额;
$event=$post;
}
//检查事件是否已通过
$gmt\u offset=(获取选项('gmt\u offset')>='0')?“+”。获取选项('gmt\u offset'):“”。获取选项('gmt\u offset');
$gmt_offset=str_replace(数组('.25'、'.5'、'.75')、数组(':15'、':30'、':45')、$gmt_offset);
if(strotime(tribe_get_end_date($event,false,'Y-m-d G:i')。$gmt_offset)
您好,谢谢您的支持解决方案是这样的。谢谢您的支持
<?php
if (tribe_is_past_event()){
echo "no option";
}
else{?>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="buy_ticket">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="aatul1031@gmail.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="<?php the_title()?>">
<input type="hidden" name="amount" value="<?php echo str_replace("$", "",tribe_get_cost( null, true )) ?>">
<input type="hidden" name="return" value="<?= home_url();?>">
<input type="hidden" name="cancel_return" value="<?php global $wp;
echo home_url( $wp->request )?>">
<div class="buy_btn">
<input type="image" src="" border="0" name="submit" alt="Buy Tickets">
</div>
</form>
<?php }?>
function\u exists
检查函数是否存在……您已经定义了functiontribe\u是过去的事件
,所以第一个条件正在执行,为什么它要执行else
条件?如果else部分输出一个空白表单,执行时它应该显示**不可见**。检查输出页面的HTML源代码以确保它根本不工作,或者它工作,但结果不可见。我想您只需要调用一个函数并检查它的结果:if(tribe_是_pass_event()){}
u_mulder@Thanks人
<?php
if (tribe_is_past_event()){
echo "no option";
}
else{?>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="buy_ticket">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="aatul1031@gmail.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="<?php the_title()?>">
<input type="hidden" name="amount" value="<?php echo str_replace("$", "",tribe_get_cost( null, true )) ?>">
<input type="hidden" name="return" value="<?= home_url();?>">
<input type="hidden" name="cancel_return" value="<?php global $wp;
echo home_url( $wp->request )?>">
<div class="buy_btn">
<input type="image" src="" border="0" name="submit" alt="Buy Tickets">
</div>
</form>
<?php }?>