我正在制作一个WordPress主题,我想编辑标题头所在的页面。(更具体地说,我正在研究"2013"主题)。现在,我只想删除主页上写着"home"的标题。但是,我不能这样做,因为这会删除所有页面中的所有标题。所以我必须写一个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 -->
我发现函数the_title()
给你的页面标题。只需使用它并将您的HTML代码放在if块之间即可自定义它。
<?PHP if(the_title() === 'home' /* is_home() */): ?>
... <!-- your html -->
<?PHP endif; ?>
您可以通过使用is_home()
方法来实现。下面是对该方法的引用。
<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 ?>