【发布时间】:2019-10-30 20:24:15
【问题描述】:
我正在使用自定义简码在我的内容中显示引导模式。问题是,<div> 破坏了内容。见这里:Output content of WordPress Shortcode in text and footer
No2 我想更改简码,只显示 Modal 的链接,并在内容后显示 modal-<div>。
为此,我检查内容字段是否有短代码,如果是,我会在内容之后显示所有模式。
下面是代码: (部分来自这里:https://stackoverflow.com/a/18196564/1788961)
$content = get_sub_field("textfield");
//write the begining of the shortcode
$shortcode = 'term';
$check = strpos($content,$shortcode);
if($check=== false) {
//echo '<h1>NO Shortcode</h1>';
} else {
//echo '<h1>HAS Shortcode</h1>';
$str = '[term value="Term Name" id="600"][term value="Another Term" id="609"]';
preg_match_all('~\[term value="(.+?)" id="(.+?)"]~', $str, $matches);
var_dump($matches[2]);
foreach($matches[2] as $match){
echo
'<div class="modal fade" id="termModal_'.$match.'" tabindex="-1" role="dialog" aria-labelledby="termModal_'.$match.'_Title" aria-hidden="true">
(rest of modal)
</div>
';
}
}
到目前为止一切正常。但现在我需要内容字段中的简码。
我不知道如何获得它们。这是我的简码:
[term value="Custom Link Title" id="123"]
我需要内容中每个短代码的 id 并将它们存储在 `$str' 变量中。
【问题讨论】:
标签: php wordpress shortcode wordpress-shortcode