无法删除WordPress页面标题而不删除内容
问题描述:
我使用Underscores.me框架制作WordPress主题。无法删除WordPress页面标题而不删除内容
我不希望显示在页面的页面标题。所以我想我可以利用一些简单的CSS来做到这一点:
.entry-title {display:none;}
但这样做也删除了相关网页上的所有内容基本上只是显示一个空白页。
后来我想我可以在我的主题删除这个去掉标题:
<header class="entry-header">
<?php the_title('<h1 class="entry-title">', '</h1>'); ?>
</header><!-- .entry-header -->
但除去上述还会从显示的所有内容。
它像标题是为了展示内容显示。我以前从未遇到过这个问题,并且我已经用Underscores.me开发了一些主题。但它就像新版本必须显示页面标题才能显示内容。
有没有人知道该怎么办?
我在本地主机上运行,所以我不能证明我的问题,但我使用了最新的主题从Underscores。
即使我安装一个“禁用页面标题”插件插件禁用冠军时,也删除内容。
我真的很希望有人有过这个问题! :)
额外的信息:
这是page.php文件看起来的样子:
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('template-parts/content', 'page'); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if (comments_open() || get_comments_number()) :
comments_template();
endif;
?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
这是它要求的模板:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title('<h1 class="entry-title">', '</h1>'); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages(array(
'before' => '<div class="page-links">' . esc_html__('Pages:', 'open2day'),
'after' => '</div>',
));
?>
</div><!-- .entry-content -->
正如我所说的,如果我用CSS删除标题,它也删除了内容。
答
请使用!在你的CSS像下面 希望这将工作重要。
.entry-title {display:none !important;}
答
当你注释掉以下行:
<?php the_title('<h1 class="entry-title">', '</h1>'); ?>
您的页面不再有类“条目标题”的H1元素。
你的CSS是期待这个元素在您的网页上,所以除非你想编辑你的CSS,你可以添加以下空元素:
<h1 class="entry-title"></h1>
这应该解决您的问题,并允许内容隐藏页面标题时显示。
最后一个模板,内容page.php文件,丢掉了最后,它一直是你的复制/粘贴错误,或者这是真的在模板中缺少什么? – ThemesCreator
尝试仅评论具有'the_title()'的PHP命令。也就是说,不要删除它周围的''标签;只是注释掉PHP命令。 –
PaulJ
@ThemesCreater不会丢失我只是忘了复制/粘贴 – user3414678