英文:
how to return vc_link in wp bakery
问题
我正在尝试在wpbakery构建器中创建自定义元素,其中我正在添加文本字段、图像和URL。一切都正常工作,只是在URL上有一个问题。有人可以帮我解决这个问题吗?
以下是我正在尝试的代码:
add_shortcode('expert', 'expert_func');
function expert_func($atts, $content = null) { // 添加了新的函数参数$content!
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;
}
//后端
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" => __(""),
),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Expert Name", "my-text-domain"),
"param_name" => "expert_name",
"value" => "",
),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Expert Designation", "my-text-domain"),
"param_name" => "expert_designation",
"value" => "",
),
array(
"type" => "attach_image",
"holder" => "div",
"class" => "",
"heading" => __("Add Year of Expirience image", "my-text-domain"),
"param_name" => "expert_exp_image",
"value" => "",
),
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Expert's Expirience Short Description", "my-text-domain"),
"param_name" => "expert_short_desc",
"value" => "",
),
array(
"type" => "textarea",
"holder" => "div",
"class" => "",
"heading" => __("Short Description of Expert", "my-text-domain"),
"param_name" => "expert_description",
"value" => "",
),
array(
"type" => "vc_link",
"holder" => "div",
"class" => "",
"heading" => __("Choose Redirect URL", "my-text-domain"),
"param_name" => "url",
"value" => "",
"description" => __("Add Short Description", "my-text-domain"),
)
)
));
}
我只想要返回所选的URL。我是WordPress的新手。谢谢您的帮助。
英文:
I am trying to create custom element in wpbakery builder in which i am adding textfield, image and url. Evrything is working fine just there is one issue in url . can anybody please help me out to solve this issue.
Below is the code i am trying :
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" )
)
)
) );
}
All i want is to return URL selected. i am new in wordpress.
Thank you in advance.
答案1
得分: 3
你没有提取你的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);
// 你的代码...
if (isset($url_link['url'])) {
$result .= '<a href="'.esc_url($url_link['url']).'" class="learn-btn">'.$url_link['title'].'</a>';
}
// 你的其他代码...
}
英文:
You are not extracting your URL so if( !empty($url) ) {
wont fire, you should add all your variables to your extract code.
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...
}
答案2
得分: 0
可以检查(附有截图)
$use_link = true;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论