dqp4933 2016-09-11 14:25
浏览 47
已采纳

Wordpress:博客和首页的条件语句相同吗?

I have added a video to the homepage header of my wordpress theme but it also displays on the blog page.

my php is

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 {}
?>

Now if i try only is_front_page it doesn’t appear on the homepage, if I try is_home it work but also shows up on the blog page.

I want the header on the blog page to be a standard header image, and I just want the homepage to display the video from the code I have included. Do I need to switch the conditional statement to a different order, or do I have the syntax completely wrong?

Thanks,

  • 写回答

3条回答 默认 最新

  • duan1933 2016-09-11 15:14
    关注

    The basic difference between the is_home() and is_front_page() is as follows.

    is_home()

    The blog homepage is the page that shows the time-based blog content of the site.

    is_home() is dependent on the site’s “Front page displays” Reading Settings ‘show_on_front’ and ‘page_for_posts’.

    If a static page is set for the front page of the site, this function will return true only on the page you set as the “Posts page”.

    is_front_page()

    This Conditional Tag checks if the main page is a posts or a Page. This is a boolean function, meaning it returns either TRUE or FALSE. It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to "Your latest posts", or when is set to "A static page" and the "Front Page" value is the current Page being displayed.

    Hence now the code is as follows.

    <?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
    }
    ?>
    

    Hence it depends on the situation of how you need to display the video over the page and to toggle around the condition that works on.

    Or you try is_page() condition and that will make up the trick for you.

    // When any single Page is being displayed.

    is_page();
    

    // When Page 42 (ID) is being displayed.

    is_page( 42 );
    

    // When the Page with a post_title of "Contact" is being displayed.

    is_page( 'Contact' );
    

    // When the Page with a post_name (slug) of "about-me" is being displayed.

    is_page( 'about-me' );
    

    Hope this explanation would be clear for you to understand better.

    Thanks:) Happy coding.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程