Return 具有相同短代码的多个结果
Return multiple results with same short code
我在 functions.php
中添加了一个函数,对于 $link
中提到的 link 的一个结果,它工作正常,但是我试图显示类似 link 的多个结果] 具有此功能。尝试通过在 $link2
中添加第二个 link 来返回带有两个变量 $atlantic1
和 $atlantic2
的数组,还尝试使用新的短代码为第二个结果创建另一个函数,但没有任何效果。
解决这个问题的最佳方法是什么?
function fish($bubbles) {
extract(shortcode_atts(array(
"fin" => get_option('pacific'),
), $bubbles));
$width = " width=\"".$fin['width']."\"";
$height = " height=\"".$fin['height']."\"";
$osorientation = " orientationMode=\"manual\"";
$link = "https://pacific.local/item/1/A";
$path = parse_url($link, PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
wp_enqueue_script( 'some-pacific-js' );
$atlantic = "<fish-info fAdd=\"".$segments[2]."\" fId=\"".$segments[3]."\" network=\"".$network."\"></fish-info>";
return $atlantic;
}
add_filter('widget_text', 'do_shortcode');
add_shortcode('pacific', 'fish');
首选方法是将 link
作为简码的参数传递,然后使用特定的 link.
调用简码两次
首先,改变fish函数:
function fish($atts) {
// Pay attention, I removed "extract" so $fin is now a key inside $atts
$atts = shortcode_atts( array(
'fin' => get_option('pacific'),
'item' => 'CHOOSE_A_DEFAULT'
), $atts );
$width = " width=\"".$atts['fin']['width']."\"";
$height = " height=\"".$atts['fin']['height']."\"";
$osorientation = " orientationMode=\"manual\"";
$link = "https://pacific.local/item/" . $atts['item'];
$path = parse_url($link, PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
wp_enqueue_script( 'some-pacific-js' );
$atlantic = "<fish-info fAdd=\"".$segments[2]."\" fId=\"".$segments[3]."\"
network=\"".$network."\"></fish-info>";
return $atlantic;
}
在您调用短代码的小部件中,您可能有这样的东西:
[pacific]
你必须把它改成这样:
[pacific item="1/A"]
[pacific item="2/B"]
我在 functions.php
中添加了一个函数,对于 $link
中提到的 link 的一个结果,它工作正常,但是我试图显示类似 link 的多个结果] 具有此功能。尝试通过在 $link2
中添加第二个 link 来返回带有两个变量 $atlantic1
和 $atlantic2
的数组,还尝试使用新的短代码为第二个结果创建另一个函数,但没有任何效果。
解决这个问题的最佳方法是什么?
function fish($bubbles) {
extract(shortcode_atts(array(
"fin" => get_option('pacific'),
), $bubbles));
$width = " width=\"".$fin['width']."\"";
$height = " height=\"".$fin['height']."\"";
$osorientation = " orientationMode=\"manual\"";
$link = "https://pacific.local/item/1/A";
$path = parse_url($link, PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
wp_enqueue_script( 'some-pacific-js' );
$atlantic = "<fish-info fAdd=\"".$segments[2]."\" fId=\"".$segments[3]."\" network=\"".$network."\"></fish-info>";
return $atlantic;
}
add_filter('widget_text', 'do_shortcode');
add_shortcode('pacific', 'fish');
首选方法是将 link
作为简码的参数传递,然后使用特定的 link.
首先,改变fish函数:
function fish($atts) {
// Pay attention, I removed "extract" so $fin is now a key inside $atts
$atts = shortcode_atts( array(
'fin' => get_option('pacific'),
'item' => 'CHOOSE_A_DEFAULT'
), $atts );
$width = " width=\"".$atts['fin']['width']."\"";
$height = " height=\"".$atts['fin']['height']."\"";
$osorientation = " orientationMode=\"manual\"";
$link = "https://pacific.local/item/" . $atts['item'];
$path = parse_url($link, PHP_URL_PATH);
$segments = explode('/', rtrim($path, '/'));
wp_enqueue_script( 'some-pacific-js' );
$atlantic = "<fish-info fAdd=\"".$segments[2]."\" fId=\"".$segments[3]."\"
network=\"".$network."\"></fish-info>";
return $atlantic;
}
在您调用短代码的小部件中,您可能有这样的东西:
[pacific]
你必须把它改成这样:
[pacific item="1/A"]
[pacific item="2/B"]