gpt4 book ai didi

php - 检查请求的 url 中的文本模式,然后执行某些操作

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:07:29 27 4
gpt4 key购买 nike

我正在使用下面的代码在我的 WordPress 网站上执行视频短代码,但有些页面已经包含手动添加的视频,这会在我使用代码时导致重复。

如何检查页面是否已经包含 YouTube 嵌入式 iframe 或视频链接,并排除已经有视频的页面,以下是我的内容:

if (is_single() && in_category(1) ) 
{
echo '<h4 class="post-title entry-title">Video</h4>' ;
echo do_shortcode( '[yotuwp type="keyword" id="'.get_post_field( 'post_title', $post_id, 'raw' ).'" player="mode=large" template="mix" column="1" per_page="1"]' );
}

我想在此处包括 youtube 链接检查:

 if (is_single() && in_category(1)

这是我能找到的Here但这会扫描请求的 url 而不是其中的内容:

<?php
if (stripos($_SERVER['REQUEST_URI'],'tout') == true && stripos($_SERVER['REQUEST_URI'],'dedans') == true)
{echo '<div class="clear"></div><a href="http://www.example.com/cakes/" class="btn"> >> View all Cakes</a>';}
?>

最佳答案

因为您已经有了 $post_id,我建议您获取 Post 对象并对“youtube”或短 URL 版本“youtu.be”进行正则表达式匹配。查看示例代码:

$post = get_post($post_id);
$content = apply_filters('the_content', $post->post_content);

if (is_single() && in_category(1) && !preg_match('/youtu\.?be/', $content)) {
echo '<h4 class="post-title entry-title">Video</h4>';
echo do_shortcode('[yotuwp type="keyword" id="' . get_post_field('post_title', $post_id, 'raw') . '" player="mode=large" template="mix" column="1" per_page="1"]');
}

关于php - 检查请求的 url 中的文本模式,然后执行某些操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53829055/

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