帮助在发布内容区域之外执行短代码

发布于 2024-10-07 15:53:32 字数 1099 浏览 5 评论 0原文

首先,我使用这个插件

http://wordpress.org/extend/plugins /my-youtube-播放列表/ &这个主题, www.press75.com/themes/on-demand/this-is-a-sample-video-post-4/

我的目的是让 YouTube 播放列表显示在主题的灰色区域,目前只有 1 个视频显示。我的目的是使用主题的 Youtube 代码嵌入字段作为我可以放置插件短代码的地方,因此让插件创建帖子所需的播放列表。但是,一旦插件未放置在帖子的内容区域中,我就无法让插件执行短代码。

一旦发布视频链接或在主题的相关字段中输入视频嵌入代码,主题就会创建一个视频容器 Div(视频的灰色区域)。

我已尝试将以下

  • [myyoutubeplaylist LO3n67BQvh0, WGOohBytKTU, iwY5o2fsG7Y, PyKNxUThW4E, 1cX4t5-YpHQ, SJ183htYl-8, eWwoHPrrJYY, bja2ttzGOFM] 硬编码到单个帖子php文件中,看看是否插头会接住它。没有运气。它只是将短代码输出到屏幕

  • Hardcoding 看看它是否会拾取它。没有运气。它只是将短代码输出到屏幕。

  • 让模板将短代码参数转储为以下内容:
    ID); ?>。运气不好。它只是将短代码输出到屏幕

  • 在视频之外重复上述所有内容由主题创建的容器 div

我刚刚没有想法,因此非常感谢任何和所有帮助

To Begin, I'm using this plugin

http://wordpress.org/extend/plugins/my-youtube-playlist/
& this theme,
www.press75.com/themes/on-demand/this-is-a-sample-video-post-4/

My intention is to have the youtube playlist displayed in the gray area on the theme, where there is currently only 1 video displayed. my intention was to use the Youtube Code embed field of the theme as the place where i could put the plugin shortcode and therefore have the plugin create the playlist needed for the post. However I've been unable to get the plugin to execute the shortcode once it is NOT placed in the content area of the post.

The theme creates a video container Div (the gray area for the video) once either a video link is posted or video embed code is entered into the relevant field of the theme.

I've tried the following

  • Hardcoding the [myyoutubeplaylist LO3n67BQvh0, WGOohBytKTU, iwY5o2fsG7Y, PyKNxUThW4E, 1cX4t5-YpHQ, SJ183htYl-8, eWwoHPrrJYY, bja2ttzGOFM] into the single post php file to see if the plug would pick it up. No Luck. It simply output the shortcode to the screen

  • Hardcoding <?php echo do_shortcode('[myyoutubeplaylist LO3n67BQvh0, WGOohBytKTU, iwY5o2fsG7Y, PyKNxUThW4E, 1cX4t5-YpHQ, SJ183htYl-8, eWwoHPrrJYY, bja2ttzGOFM]'); ?> to see if it would pick it up. No Luck. It simply outputs the shortcode to the screen.

  • Having the template dump the shortcode parameters into the following:
    <?php echo do_shortcode( get_video($post->ID); ?>. No Luck. It simply outputs the shortcode to the screen

  • Repeating all the above outside of the video container div created by the theme

I'm fresh out of idea's, so any and all help would be GREATLY appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

深居我梦 2024-10-14 15:53:33

或者尝试这个 - TubePress

您可以通过多种方式将其编码到您的主题中,并且您可以使用CSS轻松编辑它的外观...

编辑:如何在帖子/页面之外嵌入tubepress短代码(它在我看来,其中一些是专业版附带的)

or try this one - TubePress

you can code it into your theme in several ways, and you can easily edit it's appearance with CSS...

edit: how to embedd tubepress shortcode outside post/page (it looks to me like some of this comes with pro version tho)

迷乱花海 2024-10-14 15:53:33

我知道这个问题现在已经相当老了,但由于没有一个答案能解决这个问题,我将考虑提供一些关于它的见解。

如果您尝试将内容中的短代码放置到主题中的另一个区域,则需要注册一个过滤器并在您希望运行短代码的位置添加调用。假设我们想要一个与您在问题中尝试执行的功能类似的短代码 - 但我将从头开始为任何感兴趣的人提供帮助。

我们首先注册一个新的短代码,以从直接 YouTube 链接输出视频,例如 https: //www.youtube.com/watch?v=eh7lp9umG2I 这样用户就不必手动进行任何解析(我们实际上只需要最后一个参数)。

之后我们需要注册一个过滤器。在这种情况下,由于我们希望将该视频从内容中取出并将其放在其他地方,因此我们将对“the_content”应用过滤器。

接下来,我们将创建一个函数,以确保在过滤器将其删除之前获取短代码的副本 - 只是保持所有内容干燥。

最后我们只需要输出视频即可。

function your_shortcode_handler($atts)
{
    $url = $atts['video'];

    if (isset($url))
    {
        $type = 'application/x-shockwave-flash';
        $url  = str_replace("watch?v=", 'v/', $url);

        $obj  = "<object data='$url' type='$type'><param name='src' value='$url' /></object>"

        return $obj;
    }
}

add_shortcode('your_shortcode_name', 'your_shortcode_handler');

function your_shortcode_filter($content)
{
    $pattern = "/\[your_shortcode_name(.*?)\]/";

    $content = preg_replace($pattern, '', $content);

    return $content;
}

add_filter('the_content', 'your_shortcode_filter');

function stealFromContent($content)
{
    $pattern = "/\[your_shortcode_name(.*?)\]/";
    $match = null;

    preg_match($pattern, $content, $match);

    if (is_array($match) and $match[0] != '')
    {
        return $match[0];
    }

    return '';
}

//somewhere in the template you're wanting to add the video to
//BEFORE the_content is called.
$youtube_video = stealFromContent();

//then

echo $youtube_video; //wherever you want it.

现在回答作者的问题。编写此插件的特定类型的人不使用短代码。他正在对 the_content 进行重新调整,类似于我上面所做的,然后将这些值传递给 JavaScript 库。

当调用 do_shortcode 时,它​​会解析所有短代码并忽略非短代码值。一个很好的提示是,您提供的短代码根本不是短代码 - [word space word space] 无效。

源文件供参考。

I know this question is fairly old now but as none of the answers have resolved it I'll see about providing some insight on it.

If you're trying to place a shortcode from your content in to another area in your theme you'll need to register a filter and add the call where you want the shortcode to be run. Let's say that we would like a shortcode with a similar functionality as what you're trying to do in your question - but I'm going to start it at the beginning for anyone who's interested.

We'll start by registering a new shortcode to output a video from a direct YouTube link such as this https://www.youtube.com/watch?v=eh7lp9umG2I so that users don't have to do any parsing by hand (we really only need the last parameter).

After this we'll need to register a filter. In this case since we're wanting to take this video out of the content and put it somewhere else we'll be applying a filter on 'the_content'.

Next we'll create a function to make sure we grab a copy of the shortcode before the filter removes it - just keeping everything DRY.

Lastly we simply need to output the video.

function your_shortcode_handler($atts)
{
    $url = $atts['video'];

    if (isset($url))
    {
        $type = 'application/x-shockwave-flash';
        $url  = str_replace("watch?v=", 'v/', $url);

        $obj  = "<object data='$url' type='$type'><param name='src' value='$url' /></object>"

        return $obj;
    }
}

add_shortcode('your_shortcode_name', 'your_shortcode_handler');

function your_shortcode_filter($content)
{
    $pattern = "/\[your_shortcode_name(.*?)\]/";

    $content = preg_replace($pattern, '', $content);

    return $content;
}

add_filter('the_content', 'your_shortcode_filter');

function stealFromContent($content)
{
    $pattern = "/\[your_shortcode_name(.*?)\]/";
    $match = null;

    preg_match($pattern, $content, $match);

    if (is_array($match) and $match[0] != '')
    {
        return $match[0];
    }

    return '';
}

//somewhere in the template you're wanting to add the video to
//BEFORE the_content is called.
$youtube_video = stealFromContent();

//then

echo $youtube_video; //wherever you want it.

Now to answer the author's question. The select type of individual who wrote this plugin isn't using a shortcode. He is regexing over the_content similar to what I'm doing above and then passing those values to a javascript library.

When do_shortcode is called it parses all of the shortcodes and ignores the non shortcode values. A good hint was the fact that the shortcode you're providing simply isn't a shortcode - [word space word space] is invalid.

The source file for reference.

自由如风 2024-10-14 15:53:33
<?php echo myYoutubePlaylist('[myyoutubeplaylist WnY59mDJ1gg, bKwQ_zeRwEs]'); ?>
<?php echo myYoutubePlaylist('[myyoutubeplaylist WnY59mDJ1gg, bKwQ_zeRwEs]'); ?>
优雅的叶子 2024-10-14 15:53:32

将其放入您的functions.php 文件中:

add_filter('widget_text', 'do_shortcode');

然后像在主要内容区域中一样在侧边栏中使用短代码。

Put this in your functions.php file:

add_filter('widget_text', 'do_shortcode');

Then use the shortcode in your sidebar as you would in the main content area.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文