【问题标题】:Customizing WordPress theme (Twenty Thirteen). How to remove one title from the header without removing them all自定义 WordPress 主题(二十三)。如何从标题中删除一个标题而不将它们全部删除
【发布时间】:2015-07-31 19:19:25
【问题描述】:

我正在开发一个 WordPress 主题,我想编辑标题所在的页面。 (更具体地说,我正在研究“二十三”主题)。现在,我只想删除主页中显示“主页”的标题。但是,我不能这样做,因为这会删除所有页面中的所有标题。所以我必须做一个 if/else 声明。问题是对我没有任何帮助 - 下面粘贴的是代码:

<header class="entry-header">
    <?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
    <div class="entry-thumbnail">
        <?php the_post_thumbnail(); ?>
    </div>
    <?php endif; ?>

    <h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我发现函数 the_title() 给你页面标题。只需使用它并将您的 html 代码放在 if 块之间即可对其进行自定义。

    <?PHP if(the_title() === 'home' /* is_home() */): ?>
    ... <!-- your html -->
    <?PHP endif; ?>
    

    【讨论】:

    • @SamerElSabeh 很高兴听到这个家伙! ;)
    【解决方案2】:

    您可以通过使用is_home() 方法来实现。 这是该方法的reference

    <header class="entry-header">
    <?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
    <div class="entry-thumbnail">
        <?php the_post_thumbnail(); ?>
    </div>
    <?php endif;if(!is_home()):?>
    <h1 class="entry-title"><?php the_title(); ?></h1></header><!-- .entry-header --><?php endif ?>
    

    【讨论】:

    • 这也有效。我以前从未使用过 is_home() 函数。我现在正在阅读它。这真的很有帮助,我很感激。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    • 2020-04-20
    • 2014-09-03
    • 1970-01-01
    相关资源
    最近更新 更多