admin管理员组文章数量:1298409
I've made a child theme of Twenty Twenty theme and want to display the posts/ category archive pages in flexbox grid.
However, none of the conditional tags I'm hoping to check outside the loop (is_home, is_archive, is_category) are returning true on posts page or category archive pages:
* @since Twenty Twenty 1.0
*/
get_header();
?>
<?php if ( is_archive() ): ?>
<h1>ARCHIVE</h1>
<?php endif; ?>
<?php if ( is_category() ): ?>
<h1>CATEGORY</h1>
<?php endif; ?>
<?php if ( is_home() ): ?>
<h1>HOME</h1>
<?php endif; ?>
<main id="site-content maybe-flex-directive-class-here">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
I expect either I'm missing something obvious or going about it the wrong way.
I've made a child theme of Twenty Twenty theme and want to display the posts/ category archive pages in flexbox grid.
However, none of the conditional tags I'm hoping to check outside the loop (is_home, is_archive, is_category) are returning true on posts page or category archive pages:
* @since Twenty Twenty 1.0
*/
get_header();
?>
<?php if ( is_archive() ): ?>
<h1>ARCHIVE</h1>
<?php endif; ?>
<?php if ( is_category() ): ?>
<h1>CATEGORY</h1>
<?php endif; ?>
<?php if ( is_home() ): ?>
<h1>HOME</h1>
<?php endif; ?>
<main id="site-content maybe-flex-directive-class-here">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
I expect either I'm missing something obvious or going about it the wrong way.
Share Improve this question asked Aug 11, 2022 at 1:26 MikeiLLMikeiLL 5791 gold badge8 silver badges21 bronze badges 5 |1 Answer
Reset to default 0I was going to (and actually did) delete this post, but after sleeping on it, think it might end up being of some use.
What I was missing, above, is [Template Hierarchy][1]. I was looking at the singular.php
template file, which will only ever be loaded when is_archive()
, is_home()
, etc, aren't true.
What got me is that the HTML <main>
element exists on both the index.php
and singular.php
documents in this theme.
So I was able to update the child theme's copy of index.php
:
<main id="site-content" class="flex-container">
With CSS:
.flex-container {
display: flex;
flex-direction: column;
}
/* Responsive layout - make multi-column on larger screens */
@media (min-width: 800px) {
.flex-container {
flex-direction: row;
}
}
Thanks for the solution in the comment, @bosco.
[1]: https://developer.wordpress.org/themes/basics/template-hierarchy/
本文标签: conditional tagsGetting false for ishome() on Posts page
版权声明:本文标题:conditional tags - Getting false for is_home() on Posts page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738466918a2088360.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
singular.php
– MikeiLL Commented Aug 11, 2022 at 1:41<main id="site-content">
onindex.php
as well assingular.php
. I think I will delete this post unless you feel like posting an answer. Please lmk. – MikeiLL Commented Aug 11, 2022 at 1:46