我有一个功能,这是用来显示视频,我想这个视频后显示后,它应该显示视频后结束。
我已经添加了过滤器,但视频也会在帖子之前显示。
下面是我正在使用的过滤器:
function append_the_video($content) {
global $post;
$content .= youtube_video();
return $content;
}
add_filter(\'the_content\', \'append_the_video\');
已编辑的整个函数
<?php
function youtube_video()
{
?>
<div class="post">
<?php
$newvar = urlencode(get_the_title());
include_once(ABSPATH . WPINC . \'/rss.php\');
$rss = fetch_rss(\'http://gdata.youtube.com/feeds/base/videos?q=\'.$newvar.\'&client=ytapi-youtube-search&v=2\');
$maxitems = get_option(\'novideos\');
$items =is_array($rss->items) ? array_slice($rss->items, 0, $maxitems) : \'\' ;
?>
<ul>
<?php if (empty($items)) {echo "No current video uploads by ".get_the_title();}
else foreach ( $items as $item ) : ?>
<?php
$youtubeid = strchr($item[\'link\'],\'=\');
$youtubeid = substr($youtubeid,1);
?>
<p>Latest Videos of <b><?php the_title(); ?>:</b></p>
<br>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="320" height="265">
<param name="movie" value="http://www.youtube.com/v/<?php echo $youtubeid ?>&hl=en&fs=1" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/<?php echo $youtubeid ?>&hl=en&fs=1" width="320" height="265">
<!--<![endif]-->
<p><a href="http://www.youtube.com/v/<?php echo $youtubeid ?>">View movie»</a></p>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
}
function append_the_video($content) {
global $post;
$content .= youtube_video();
return $content;
}
add_filter(\'the_content\', \'append_the_video\');
?>
最合适的回答,由SO网友:MZAweb 整理而成
2个选项:
1) 编辑youtube\\u video()函数,使其返回字符串,而不是打印代码
2) 最简单的方法。。。如果可以编辑主题,请在显示帖子内容后调用youtube\\u video()
编辑:
<?php
function youtube_video()
{
$ret = "";
$ret .= "<div class=\'post\'>";
$newvar = urlencode(get_the_title());
include_once(ABSPATH . WPINC . \'/rss.php\');
$rss = fetch_rss(\'http://gdata.youtube.com/feeds/base/videos?q=\'.$newvar.\'&client=ytapi-youtube-search&v=2\');
$maxitems = get_option(\'novideos\');
$items =is_array($rss->items) ? array_slice($rss->items, 0, $maxitems) : \'\' ;
$ret .= "<ul>";
if (empty($items)) {$ret .= " \'No current video uploads by \'.get_the_title()";}
else foreach ( $items as $item ) :
$youtubeid = strchr($item[\'link\'],\'=\');
$youtubeid = substr($youtubeid,1);
$ret .= "<p>Latest Videos of <b>" . get_the_title() . ":</b></p>";
$ret .= "<br>";
$ret .= "<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' width=\'320\' height=\'265\'>";
$ret .= "<param name=\'movie\' value=\'http://www.youtube.com/v/" . $youtubeid ."&hl=en&fs=1\' />";
$ret .= "<!--[if !IE]>-->";
$ret .= "<object type=\'application/x-shockwave-flash\' data=\'http://www.youtube.com/v/" . $youtubeid ."&hl=en&fs=1\' width=\'320\' height=\'265\'>";
$ret .= "<!--<![endif]-->";
$ret .= "<p><a href=\'http://www.youtube.com/v/" . $youtubeid ."\'>View movie»</a></p>";
$ret .= "<!--[if !IE]>-->";
$ret .= "</object>";
$ret .= "<!--<![endif]-->";
$ret .= "</object>";
$ret .= "</li>";
endforeach;
$ret .= "</ul>";
$ret .= "</div>";
return $ret;
}
?>