如何在 wp bakery 中 return vc_link
how to return vc_link in wp bakery
我正在尝试在 wpbakery 构建器中创建自定义元素,我正在其中添加文本字段、图像和 url。一切正常,只是 url 中有一个问题。谁能帮我解决这个问题。
下面是我正在尝试的代码:
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" )
)
)
) );
}
我只想return URL 选中。我是 wordpress 的新手。
提前谢谢你。
可以查看(附截图)
$use_link = true;
您没有提取 URL,因此 if( !empty($url) ) {
不会触发,您应该将所有变量添加到提取代码中。
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...
}
我正在尝试在 wpbakery 构建器中创建自定义元素,我正在其中添加文本字段、图像和 url。一切正常,只是 url 中有一个问题。谁能帮我解决这个问题。
下面是我正在尝试的代码:
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" )
)
)
) );
}
我只想return URL 选中。我是 wordpress 的新手。 提前谢谢你。
可以查看(附截图)
$use_link = true;
您没有提取 URL,因此 if( !empty($url) ) {
不会触发,您应该将所有变量添加到提取代码中。
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...
}