dousha2020 2015-08-03 15:20
浏览 36

Wordpress if(post_name === nameOfPost)无效

I am trying to display specific text at the bottom of a menu but I only want this text to show if I am looking at a certain menu. This is the code I have:

<?php get_post_type( $post ) ?>
<?php if ( $post->post_name === 'belden-village' ) : ?>
    <?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank You</p>"; ?>
<?php endif ?>

This code works in staging but as soon as we moved the site live it no longer displays the text when it is supposed to. I am calling it by the "slug" and the slug is the same in both staging and live site. Any ideas why this has suddenly stopped working? This is my first experience taking a site live so any help would be greatly appreciated. Thanks.

  • 写回答

1条回答 默认 最新

  • dove2199 2015-08-03 18:28
    关注

    Why not use the is_single() function?

    <?php get_post_type( $post ) ?>
        <?php if ( is_single( 'belden-village') ) : ?>
            <?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank
        You</p>"; ?>
    <?php endif ?>
    

    If you are looking for a page instead of a post you can use the is_page() function instead:

    <?php get_post_type( $post ) ?>
        <?php if ( is_page( 'belden-village') ) : ?>
            <?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank
        You</p>"; ?>
    <?php endif ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序