Php Wordpress:在帖子中循环客户变量
我正在运行一个wordpress站点,我想知道是否有可能在单个模板本身的自定义字段上执行循环 下面是我用来在帖子中呈现youtube视频的代码。我在帖子上记录的只是youtube的唯一标识符Php Wordpress:在帖子中循环客户变量,php,wordpress,Php,Wordpress,我正在运行一个wordpress站点,我想知道是否有可能在单个模板本身的自定义字段上执行循环 下面是我用来在帖子中呈现youtube视频的代码。我在帖子上记录的只是youtube的唯一标识符 <?php if ( get_post_meta($post->ID, 'video_youtube', true) ) : ?> <div class="youtube_video"> <?php echo'
<?php if ( get_post_meta($post->ID, 'video_youtube', true) ) : ?>
<div class="youtube_video">
<?php echo'
<iframe width="570" height="395" src="http://www.youtube.com/embed/';?><?php echo get_post_meta($post->ID,'video_youtube', true)?><?php echo'" frameborder=0 allowfullscreen></iframe>
';
?>
</div>
<?php endif; ?>
我想要的是,每次在该帖子上使用自定义变量“video_youtube”时,该代码都会循环
有人能提出什么建议吗 我真的不太明白,我得到的是,你需要某种方式或变量,当调用时会产生youtube iframe代码 但我不明白是由您决定在模板上使用自定义变量的次数。您确定要自定义变量吗?或者你想要短代码?可以通过post/页面或模板填写 试试这个
$youtube_embed = '
<iframe width="570" height="395" src="http://www.youtube.com/embed/'.get_post_meta($post->ID, 'video_id', true).'" frameborder=0 allowfullscreen></iframe>
';
$youtube = get_post_meta($post->ID, 'video_youtube', true)?$youtube_embed;
$youtube\u
';
$youtube=get\u post\u meta($post->ID,'video\u youtube',true)?$youtube\u嵌入;
现在,无论你想在哪里发布youtube视频,你只需回显$youtube即可
或者,如果每次需要视频时都需要传递视频ID,则可以在模板文件中创建一个小函数甚至类
function embedYoutube($video_link,$is_embed){
return '<iframe width="570" height="395"
src="http://www.youtube.com/embed/'.$video_link.'" frameborder=0 allowfullscreen></iframe>
';}
echo embedYoutube(get_post_meta($post->ID, 'video_id', true),get_post_meta($post->ID, 'video_youtube', true));
函数嵌入YouTube($video\u link,$is\u embed){
返回'
';}
echo嵌入youtube(get_post_meta($post->ID,'video_ID',true),get_post_meta($post->ID,'video_youtube',true));