【问题标题】:Auto enable embed youtube video with get_post() function使用 get_post() 函数自动启用嵌入 youtube 视频
【发布时间】:2011-07-19 21:16:00
【问题描述】:

我使用 get_post() 函数来获取特定的帖子内容。但是,我无法运行自动嵌入视频。

这里是代码

<?php
$post_id = 110;
$queried_post = get_post($post_id);
$content = $queried_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
echo $content;
?>

我希望它自动检测 youtube 链接并启用嵌入视频。 示例内容为

Check out this cool video:

http://www.youtube.com/watch?v=nTDNLUzjkpg

That was a cool video.

http://codex.wordpress.org/Function_Reference/get_post

http://codex.wordpress.org/Embeds

【问题讨论】:

    标签: php wordpress youtube embed


    【解决方案1】:

    我自己没有尝试过,但我可以告诉你:

    1. oEmbed 功能通过过滤器在 wordpress 中应用。
    2. 默认情况下get_posts() 函数会抑制过滤器,我猜get_post() 也会这样做,尽管我无法在文档中验证这一点。

    也许您可以使用query_posts()(不抑制过滤器)或get_posts()suppress_filters=&gt;false 来测试。

    【讨论】:

    • 感谢您的回答。我无法让 oEmbed 与 get_posts() 或 query_posts() 一起使用。但是,我可以让 Smart Youtube 插件与 query_posts() 一起使用
    猜你喜欢
    • 2016-11-19
    • 2016-11-27
    • 2011-07-06
    • 2017-11-17
    • 2011-02-27
    • 2011-04-24
    • 2017-11-03
    • 1970-01-01
    • 2011-10-30
    相关资源
    最近更新 更多