php 按钮短代码和vc附加组件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 按钮短代码和vc附加组件相关的知识,希望对你有一定的参考价值。
<?php
// VC button add-ons
vc_map(
array(
"name" => esc_html__( "Stock Button", "stock-toolkit" ),
"base" => "stock_btn",
"category" => esc_html__( "Stock", "stock-toolkit"),
"params" => array(
array(
"type" => "dropdown",
"heading" => esc_html__( "Link type", "stock-toolkit" ),
"param_name" => "type",
"std" => esc_html__( "1", "stock-toolkit" ),
"value" => array(
esc_html__('Link to page','stock-toolkit') => 1,
esc_html__('External link','stock-toolkit') => 2,
),
"description" => esc_html__( "", "stock-toolkit" ),
),
array(
"type" => "dropdown",
"heading" => esc_html__( "Link to page", "stock-toolkit" ),
"param_name" => "link_to_page",
"value" => stock_toolkit_get_page_as_list(),
"description" => esc_html__( "", "stock-toolkit" ),
"dependency" => array(
"element" => "type",
"value" => array("1"),
)
),
array(
"type" => "textfield",
"heading" => esc_html__( "External link", "stock-toolkit" ),
"param_name" => "external_link",
"description" => esc_html__( "", "stock-toolkit" ),
"dependency" => array(
"element" => "type",
"value" => array("2"),
)
),
array(
"type" => "textfield",
"heading" => esc_html__( "Link text", "stock-toolkit" ),
"param_name" => "link_text",
"std" => esc_html__( "See more", "stock-toolkit" ),
"description" => esc_html__( "", "stock-toolkit" ),
),
)
)
);
<?php
// Button Shortcode
function stock_btn_shortcode($atts, $content = null){
extract( shortcode_atts( array(
'type' => 1,
'link_to_page' => '',
'external_link' => '',
'link_text' => 'See more about us',
), $atts) );
if($type == 1){
$link_source = get_page_link($link_to_page);
}else{
$link_source = $external_link;
}
$stock_btn_markup = '
<a href="'.esc_url($link_source).'" class="bordered-btn">'.esc_html($link_text).'</a>
';
return $stock_btn_markup;
}
add_shortcode('stock_btn', 'stock_btn_shortcode' );
以上是关于php 按钮短代码和vc附加组件的主要内容,如果未能解决你的问题,请参考以下文章