dongqiang5865 2014-11-12 18:58
浏览 46
已采纳

如何在Visual Composer扩展的WordPress插件中访问变量?

I'm trying to extend my client's page backend with Visual Composer extended plugin. I've been following instructions given here: http://kb.wpbakery.com/index.php?title=Visual_Composer_tutorial.

The plugin shows at the WP backend and the fields I have created like this are shown:

array(
    "type" => "textfield",
    "holder" => "div",
    "class" => "",
    "param_name" => "fourth_quote",
    "value" => __("", 'vc_extend'),
    "description" => __('Fourth testimonial quote', 'vc_extend')
)

However, I don't understand how I'm supposed to access the 'fourth_quote' later on:

public function renderMyBartag( $atts, $content = null) {
  extract( shortcode_atts( array(
    'faa' => 'something',
    'color' => '#FF0000'
  ), $atts ) );

  $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content

  $output = '<div>{$fourth_quote}</div>';
  error_log(date('[ d.m.Y H:i:s ] ') . $output . PHP_EOL, 3, "my-errors.log");
  return $output;
}

This, however doesn't output anything even there is content stored.

How do I access the content user have created at the backend so I'd be able to render the page based on that? How do I get the variables?

  • 写回答

1条回答 默认 最新

  • dongzaobei0942 2014-11-12 20:28
    关注

    From http://kb.wpbakery.com/index.php?title=Visual_Composer_tutorial:

    This list represents shortcode tag as base and params list which will be editable with settings form inside js_composer constructor.

    You must add the fourth_quote attribute to the shortcode.
    For example:

    public function renderMyBartag( $atts, $content = null) {
    
        # Also, avoid using extract()
        # http://stackoverflow.com/questions/829407/what-is-so-wrong-with-extract
        # http://codex.wordpress.org/Shortcode_API
    
        $a = shortcode_atts( array(
            'faa'          => 'something',
            'color'        => '#FF0000',
            'fourth_quote' => false, // just a default value
        ), $atts );
    
        $content = wpb_js_remove_wpautop($content, true);
    
        $output = $a['fourth_quote'];
    
        error_log(date('[ d.m.Y H:i:s ] ') . $output . PHP_EOL, 3, "my-errors.log");
    
        return $output;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys