How to set up a echo?

时间:2013-03-17 作者:user1355485

我的问题是我不知道如何设置回声。我需要它只是在下面的代码周围正确地包装一个if语句,请帮助。。。非常感谢

 <?php 
global $post;
if(get_post_type($post->ID) == \'videos\')
{



<video class="video"  width="<?php  echo get_field(\'width\'); ?>" height="<?php  echo get_field(\'height\'); ?>" controls preload>

                        <source src="<?php  echo get_field(\'mp4\'); ?>" media="only screen and (min-device-width: 960px)"></source>

                        <source src="<?php  echo get_field(\'iphone\'); ?>" media="only screen and (max-device-width: 960px)"></source>

                        <source src="<?php  echo get_field(\'ogv\'); ?>"></source>

                    </video>




          <h2><?php the_title(); ?></h2>

<?php  echo get_field(\'content\'); ?>
}

?>

2 个回复
最合适的回答,由SO网友:revo 整理而成

您可以使用get_post_type() 函数并将当前的post id传递给它。

global $post;
if(get_post_type($post->ID) == \'videos\')
{
    // do this
}
Update

<?php 
global $post;
if(get_post_type($post->ID) == \'videos\')
{
?>
<video class="video"  width="<?php  echo get_field(\'width\'); ?>" height="<?php  echo get_field(\'height\'); ?>" controls preload>

                        <source src="<?php  echo get_field(\'mp4\'); ?>" media="only screen and (min-device-width: 960px)"></source>

                        <source src="<?php  echo get_field(\'iphone\'); ?>" media="only screen and (max-device-width: 960px)"></source>

                        <source src="<?php  echo get_field(\'ogv\'); ?>"></source>

                    </video>

          <h2><?php the_title(); ?></h2>

<?php  echo get_field(\'content\'); ?>
<?php
}
?>

SO网友:Vinod Dalvi

您直接在php标记中使用html标记,这就是它不能正常工作的原因。我修改了您的代码,如下所示,它嵌套良好,因此请使用以下代码。

<?php 
global $post;
if(get_post_type($post->ID) == \'videos\')
{ ?>
<video class="video"  width="<?php  echo get_field(\'width\'); ?>" height="<?php  echo get_field(\'height\'); ?>" controls preload>

                    <source src="<?php  echo get_field(\'mp4\'); ?>" media="only screen and (min-device-width: 960px)"></source>

                    <source src="<?php  echo get_field(\'iphone\'); ?>" media="only screen and (max-device-width: 960px)"></source>

                    <source src="<?php  echo get_field(\'ogv\'); ?>"></source>

                </video>




      <h2><?php the_title(); ?></h2>

<?php  echo get_field(\'content\'); ?>
<?php } ?>

结束

相关推荐