首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在wp面包房退回vc_link

如何在wp面包房退回vc_link
EN

Stack Overflow用户
提问于 2020-01-03 18:09:33
回答 2查看 1.8K关注 0票数 0

我试图在wpbakery builder中创建自定义元素,在其中我添加了文本字段、图像和url。一切都很好,只是url中有一个问题。有人能帮我解决这个问题吗?

下面是我正在尝试的代码:

代码语言:javascript
复制
add_shortcode( 'expert', 'expert_func' );
function expert_func( $atts, $content = null ) { // New function parameter $content is added!
extract(
    shortcode_atts(
      array(
        'expert_image' => 'expert_image',
        'title'   => '',
      ),
      $atts
    )
  );

  $img_url = wp_get_attachment_image_src( $expert_image, "full");

  extract(
    shortcode_atts(
      array(
        'expert_exp_image' => 'expert_exp_image',
        'title'   => '',
      ),
      $atts
    )
  );

  $exp_img_url = wp_get_attachment_image_src( $expert_exp_image, "full");



$result .='<div class="inner__card">
            <div class="expert-img">
              <img src="'. $img_url[0] .'">
            </div>
            <div class="expert-details">
              <p class="name">'.$atts['expert_name'].'</p>
              <p class="designation">'.$atts['expert_designation'].'</p>
              <div class="expect-experience">
                <div class="expect-experience-no">
                  <img src="'. $exp_img_url[0] .'" alt="experience-10">
                </div>
                <div class="expect-experience-text">
                  <p>'.$atts['expert_short_desc'].'</span></p>
                </div>
              </div>
              <p class="details">'.$atts['expert_description'].'</p>
              <div class="expert-btn">';
if( !empty($url) ){
      $column_link_array = vc_build_link($url);
      $url = $column_link_array['url'];
      $result .= "<a href='$url' class='learn-btn'></a>";
  }
$result .=' </div>
            </div>
        </div>';

 //$result = $button;

 //print_r($atts);

 return $result;

 }

 //backend
 add_action( 'vc_before_init', 'expert_integrateWithVC' );
 function expert_integrateWithVC() {
 vc_map( array(
"name" => __( "Expert", "my-text-domain" ),
"base" => "expert",
"class" => "",
"category" => __( "Custom", "my-text-domain"),
"params" => array(
array(
"type" => "attach_image",
"holder" => "div",
"class" => "",
"heading" => __( "Choose Expert Image", "my-text-domain" ),
"param_name" => "expert_image",
"value" => __( "", "my-text-domain" )

),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __( "Expert Name", "my-text-domain" ),
"param_name" => "expert_name",
"value" => __( "", "my-text-domain" )
 ),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __( "Expert Designation", "my-text-domain" ),
"param_name" => "expert_designation",
"value" => __( "", "my-text-domain" )
),
array(
"type" => "attach_image",
"holder" => "div",
"class" => "",
"heading" => __( "Add Year of Expirience image", "my-text-domain" ),
"param_name" => "expert_exp_image",
"value" => __( "", "my-text-domain" )
 ),
 array(
 "type" => "textfield",
 "holder" => "div",
 "class" => "",
 "heading" => __( "Expert's Expirience Short Description", "my-text-domain" ),
 "param_name" => "expert_short_desc",
 "value" => __( "", "my-text-domain" )
 ),
 array(
"type" => "textarea",
"holder" => "div",
"class" => "",
"heading" => __( "Short Description of Expert", "my-text-domain" ),
"param_name" => "expert_description",
"value" => __( "", "my-text-domain" )
),
 array(
 "type" => "vc_link",
 "holder" => "div",
 "class" => "",
 "heading" => __( "Choose Rediect URL", "my-text-domain" ),
 "param_name" => "url",
 "value" => __( "", "my-text-domain" ),
 "description" => __( "Add Short Description", "my-text-domain" )
 )

 )
 ) );
 }

所有我想要的是返回URL选择。我是wordpress的新手。提前谢谢你。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-03 20:49:06

你没有提取你的网址,所以if( !empty($url) ) {不会触发,你应该将所有变量添加到你的提取代码中。

代码语言:javascript
复制
function expert_func( $atts ) {

  extract( shortcode_atts( array(
    'expert_image'  => '',
    'expert_name'  => '',
    'expert_designation' => '',
    'expert_exp_image' => '',
    'expert_short_desc' => '',
    'expert_description'  => '',
    'url' => '',
  ), $atts ) );

  $img_url = wp_get_attachment_image_src( $expert_image, "full");

  $url_link = vc_build_link($url);

  your code...

  if (isset($url_link['url'])) {

    $result .= '<a href="'.esc_url($url_link['url']).'" class="learn-btn">'.$url_link['title'].'</a>';

  }

  your code etc...

}
票数 3
EN

Stack Overflow用户

发布于 2020-01-03 18:16:57

可以检查(附加屏幕截图)

代码语言:javascript
复制
$use_link = true;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59576638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档