代码之家  ›  专栏  ›  技术社区  ›  Ruslan Jackson

将php逻辑函数放入wordpress短代码中

  •  1
  • Ruslan Jackson  · 技术社区  · 7 年前

    echo do_shortcode('[ihc-hide-content ihc_mb_who="5,7"] MY CONTENT HERE [/ihc-hide-content])

    if ( $a = $b ) {    echo ($c);    }
    

    有可能以某种方式做到这一点吗? 顺便说一句,我又做了一个短码,把他放在里面,像这样:

    do_shortcode('[ihc-hide-content ihc_mb_who="5,7"].do_shortcode('[my_shortcode]').[/ihc-hide-content])
    

    但是第一个短代码并没有隐藏第二个短代码的内容。 任何帮助都将被感谢,并为我糟糕的英语道歉!

    1 回复  |  直到 7 年前
        1
  •  1
  •   Xhynk    7 年前

    如果您使用的是 Enclosing Shortcode 您应该能够将短代码作为字符串添加到 do_shortcode() 作用 怎样 这个 ihc-hide-content 设置了快捷码后,它 工作不太正常,但你也可以解决这个问题。

    do_shortcode( '[ihc-hide-content ihc_mb_who="5,7"][my_shortcode][/ihc-hide-content]' );
    

    如果这不起作用(老实说,应该如此),您可以尝试从中生成输出 my_shortcode 变成 Output Buffer

    // Turn on Output Buffering
    ob_start();
    
    // Output your shortcode
    do_shortcode( '[my_shortcode]' );
    
    // Turn off Output Buffering, and grab the content as a variable
    $my_shortcode_output = ob_get_clean();
    
    // Pass that complete output to the other shortcode
    do_shortcode( '[ihc-hide-content ihc_mb_who="5,7"]'. $my_shortcode_output .'[/ihc-hide-content]' );