因此,由于某种原因,我无法提取相同的链接属性并将它们传递到我的代码中。
所以这是短代码:
[slide headline="<h2>Title</h2>" image="https://via.placeholder.com/150" body="The text in the body" link="Test1|https://www.test1.com" link="Test2|https://test2.com"]
var_dump($atts)仅返回一个链接,如下所示:
array (size=4)
'headline' => string '</p>
<h2>Title</h2>
<p>' (length=29)
'image' => string 'https://www.raritanheadwaters.org/wp-content/uploads/2018/01/placeholder-picture-large-opt.png' (length=94)
'body' => string 'The text in the body' (length=202)
'link' => string 'Test1|https://www.test1.com' (length=61)
这是我的代码:
function slide_item_shortcode($atts, $content = null)
{
shortcode_atts([
"image" => '',
"headline" => '',
"body" => '',
"link" => '',
], $atts);
var_dump($atts);
$social_links = explode("|", $atts['link']);
return '<li class="slide">
<p><img src="' . esc_url($atts['image']) . '" alt="" /></p>
<p>'. $atts['headline'] .'</p>
<p>'. $atts['body'] .'</p>
<p>'. '<a href="' . $social_links[1] . '" target="_blank">' . $social_links[0] . '</a>' .'</p>
</li>';
}
add_shortcode('slide', 'slide_item_shortcode');
沧海一幻觉
慕村9548890