gpt4 book ai didi

javascript - 如何限制来自 WordPress 短代码的内容?

转载 作者:行者123 更新时间:2023-12-01 01:07:56 25 4
gpt4 key购买 nike

我正在开发一个 WordPress 短代码,我想限制来自 xml 的内容。 。

我用来创建 WordPress 短代码的代码是:

function podcast_func( $content = null ){
ob_start();
?>
<script src="https://content.jwplatform.com/libraries/FZ8yNTef.js"></script>
<center><div id="podcast" align="center"></div></center>
<script>
var PodcastplayerInstance = jwplayer("podcast");
PodcastplayerInstance.setup({
playlist: "http://www.cpac.ca/tip-podcast/jwplayer.xml",
androidhls: true,
preload: "auto",
height: 200,
width: 400,
visualplaylist:false,
stretching: "fill",
"plugins": {
"http://www.cpac.ca/tip-podcast/listy.js":{},
'viral-2': {'oncomplete':'False','onpause':'False','functions':'All'}
}
});
</script>
<?PHP
return ob_get_clean();
}
add_shortcode( 'podcast', 'podcast_func' );


关于使用这个:<div class="today-podcast" style="text-align: center;">[podcast]</div> ,它显示这里的全部内容 http://www.cpac.ca/tip-podcast/jwplayer.xml

问题陈述:我想知道我应该在上面的 WordPress 短代码中进行哪些更改,以便它仅显示此处的第两个项目任何单个项目 http://www.cpac.ca/tip-podcast/jwplayer.xml

enter image description here

最佳答案

最好首先将返回的 XML 保存到文件中,然后循环回取消设置。

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "http://www.cpac.ca/tip-podcast/jwplayer.xml",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"postman-token: 28025ee8-1e82-ce60-f6ae-f401118baa1c"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
$fp = fopen(ABSPATH.'jwp.xml', 'w');
fwrite($fp, $response);
fclose($fp);
}

$xml = simplexml_load_file(ABSPATH.'jwp.xml');

for($i = count($xml->channel->item); $i >= 2; $i--){
unset($xml->channel->item[$i]);
}

$xml->saveXML(ABSPATH.'jwp.xml');

?>
<script src="https://content.jwplatform.com/libraries/FZ8yNTef.js"></script>
<center><div id="podcast" align="center"></div></center>
<script>
var PodcastplayerInstance = jwplayer("podcast");
PodcastplayerInstance.setup({
playlist: "<?php echo site_url(); ?>/jwp.xml",
androidhls: true,
preload: "auto",
height: 200,
width: 400,
visualplaylist:false,
stretching: "fill",
"plugins": {
"http://www.cpac.ca/tip-podcast/listy.js":{},
'viral-2': {'oncomplete':'False','onpause':'False','functions':'All'}
}
});
</script>

如果您只需要第二个或第三个元素,请使用以下内容更新上面的代码

for($i = count($xml->channel->item); $i >= 3; $i--){
unset($xml->channel->item[$i]);
}

for($i = 0; $i < count($xml->channel->item); $i++){
unset($xml->channel->item[0]);
}

关于javascript - 如何限制来自 WordPress 短代码的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55446316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com