【问题标题】:Check if variable used to trigger popup检查变量是否用于触发弹出窗口
【发布时间】:2026-02-08 15:35:01
【问题描述】:

您好,我正在开发一个 wordpress 网站,如果简码中的 arrtibute 设置为“popup="register"),我目前设置了一个弹出窗口...我添加了另一个我想显示的灯箱,如果属性设置为“popup="apply")

我的问题是如何向以下函数添加另一个变量。我需要一个 if 语句吗?我是 php 新手,非常感谢任何建议。谢谢!!!!

function oxy_shortcode_button_fancy($atts , $content = '' ) {
     // setup options
    extract( shortcode_atts( array(
        'button_swatch'     => 'swatch-coral',
        'button_animation'  => '',
        'size'              => 'default',
        'xclass'            => '',
        'link'              => '',
        'label'             => 'My button',
        'icon'              => '',
        'link_open'         => '_self',
        'popup'             => ''
    ), $atts ) );

    $popup = ('register' == $popup) ? ' onclick="jQuery(\'#registerid, .overlayLogin\').show();"' : '';
    $animation = ( $button_animation != "") ? ' data-animation="'.$button_animation.'"' :"";
    return '<a'.$popup.' href="'. $link .'" class="btn '. $size.' btn-icon-right '. $xclass . ' '. $button_swatch .'" target="' . $link_open . '"> '. $label . '<span><i class="'.$icon.'" '.$animation.'></i></span></a>';



    }

我要补充的是:

$popup = ('apply' == $popup) ? ' onclick="jQuery(\'#applyid, .overlayLogin\').show();"' : '';

【问题讨论】:

  • 你是对的..按照你提到的方式做
  • @VaibhavBhanushali 添加到第一个 $popup = ('register' == $popup) 正下方时不起作用....
  • 你用 if else 语句检查了吗?

标签: php wordpress if-statement


【解决方案1】:

尝试使用此代码..希望对您有所帮助

  function oxy_shortcode_button_fancy($atts , $content = '' ) {
 // setup options
extract( shortcode_atts( array(
    'button_swatch'     => 'swatch-coral',
    'button_animation'  => '',
    'size'              => 'default',
    'xclass'            => '',
    'link'              => '',
    'label'             => 'My button',
    'icon'              => '',
    'link_open'         => '_self',
    'popup'             => ''
), $atts ) );


 if('register' == $popup) {
$popup = ('register' == $popup) ? ' onclick="jQuery(\'#registerid, .overlayLogin\').show();"' : '';
} else {
$popup = ('apply' == $popup) ? ' onclick="jQuery(\'#applyid, .overlayLogin\').show();"' : '';
}
$animation = ( $button_animation != "") ? ' data-animation="'.$button_animation.'"' :"";
return '<a'.$popup.' href="'. $link .'" class="btn '. $size.' btn-icon-right '. $xclass . ' '. $button_swatch .'" target="' . $link_open . '"> '. $label . '<span><i class="'.$icon.'" '.$animation.'></i></span></a>';



}

【讨论】: