php - 使用相同的短代码返回多个结果
问题描述
我在其中添加了一个函数functions.php
,它适用于一个带有提到的链接的结果,$link
但是我试图用这个函数显示来自类似链接的多个结果。尝试使用两个变量返回数组$atlantic1
并$atlantic2
添加第二个链接$link2
,还尝试使用新的短代码创建另一个函数以获得第二个结果,但没有任何效果。
解决此问题的最佳方法是什么?
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
作为简码的参数传递,然后使用特定链接调用简码两次。
首先,改变鱼功能:
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"]
推荐阅读
- python - 使用漂亮的汤来模拟页面点击以访问页面上的所有 HTML?
- excel - 总和基于 Sl No 的偏移量
- youtube - 是否有一个 youtube API 可以“关注”评论?
- r - 根据来自多个变量的多个观察值用 3 个可能的字符串填充一个变量
- email - 无法在 Postfix 上使用 StartTLS 发送
- python - 如果 A 列具有相同的日期但不同的时间,则在 B 列中取平均值
- r - 如何将列表中的矩阵循环转换为列表中的 igraph?
- makefile - 将命令输出保存到 Makefile 变量时如何保留空格?
- matlab - 如何使用 MATLAB rand 函数在给定网格中生成随机点?
- marklogic - 如何将默认 MarkLogic 日志更改为不同的位置