我在wordpress主题的主页标题中添加了一个视频,但它也显示在博客页面上。
我的php是
if ( is_home() || is_front_page() ) {
echo '
<div class="overlay-caption">
<h1 class="home-h1">Join Us</h1>
With over 30 years of experience your adventure with us will be fun, memorable and help you pursue your passion for photography.
</div>
<div class="videoWrapper">
<iframe width="560" height="315" src="https://www.youtube.com/embed/3tmFvHviYcY?rel=0&autoplay=1&modestbranding=1&controls=0&loop=1&playlist=3tmFvHviYcY" frameborder="0" allowfullscreen autoplay="1"></iframe>
</div>';
}
else {}
?>
现在,如果我只尝试is_front_page,它不会出现在主页上,如果我尝试is_home它可以正常工作,但也会显示在博客页面上。
我希望博客页面上的标题是标准的标题图像,我只希望主页显示我所包含的代码中的视频。我是否需要将条件语句切换到不同的顺序,或者我的语法是否完全错误?
谢谢,
答案 0 :(得分:0)
这里的陈述顺序很重要,请尝试翻转它们,例如:
if(is_front_page() || is_home())
您也可以使用:
if(!is_front_page() && is_home())
答案 1 :(得分:0)
尝试这样的事情
$errMSG
答案 2 :(得分:0)
is_home()
和is_front_page()
之间的基本区别如下:
<强> is_home()强>
博客主页是显示网站基于时间的博客内容的页面。
is_home()依赖于网站的“首页显示”阅读设置'show_on_front'和'page_for_posts'。
如果为网站的首页设置了静态页面,则此功能仅在您设置为“帖子页面”的页面上返回true。
<强> is_front_page()强>
此条件标记检查主页是帖子还是页面。这是一个布尔函数,意味着它返回TRUE或FALSE。当显示主博客页面并且Settings->Reading->Front page
显示设置为“您的最新帖子”时,或者当设置为“静态页面”并且“首页”值是当前页面时,它返回TRUE显示。
因此现在代码如下。
<?php
if(is_front_page() || is_home())
{
// The Code will execute if it is a 'Front Page'
// OR
// if the page is a 'Home Page'
}
if(is_front_page() && is_home())
{
// Here the code will execute if the page is
// A Front Page and as well as the Home Page
}
?>
因此,它取决于您需要如何在页面上显示视频以及切换工作条件的情况。
或者您尝试is_page()
条件,这将为您解决问题。
//显示任何单个页面时。
is_page();
//正在显示第42页(ID)。
is_page( 42 );
//当显示带有“联系人”的post_title的页面时。
is_page( 'Contact' );
//当显示名为“about-me”的post_name(slug)的页面时。
is_page( 'about-me' );
希望这个解释清楚明白,让您更好地理解。
谢谢:)快乐的编码。