WordPress 中的条件标头
我试图为主页和其他任何内容显示两个不同的标题。 我在wordpress设置>中设置阅读:主页作为“静态页面”,我发布的页面名为“主页”。 我的代码应在主页中显示 和 在所有其他页面或帖子中。 该代码似乎不起作用,并在所有页面(包括主页)上显示
。
我的代码
<header id="masthead" class="site-header">
<div class="site-branding">
<?php
if ( is_front_page() && is_home() ) :
?>
<div class="home_topbar">
<div class="contatti_sx">
<address>Via Indirizzo, 2, 00000 Paese RE</address><a href="tel:+393335554444">+39 333 555 4444</a>
</div>
<div class="socials">
<a href="https://www.facebook.com"><i></i></a>
<a href="https://www.instagram.com"><i></i></a>
</div>
<div class="language">
<a href="">IT</a><a href="">EN</a>
</div>
</div>
<div class="copertina">
<h4>EMILIA - La Bassa</h4>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<img src="<?php the_post_thumbnail() ?>" alt="">
</div>
<div class="menu_bar">
<div class="logo"><?php the_custom_logo(); ?></div>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'cdnonni' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
<div><a href="prenotazioni" class="prenotazioni"></a></div>
</div>
<?php
else :
?>
<div class="page_topbar">
<div class="contatti_sx">
<address>Via Indirizzo, 2, 00000 Paese RE</address><a href="tel:+393335554444">+39 333 555 4444</a>
</div>
<h1 class="topbar_title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<div class="socials">
<a href="https://www.facebook.com"><i></i></a>
<a href="https://www.instagram.com"><i></i></a>
</div>
<div class="language">
<a href="">IT</a><a href="">EN</a>
</div>
</div>
<div class="menu_bar">
<div class="logo"><?php the_custom_logo(); ?></div>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'cdnonni' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
<div><a href="prenotazioni" class="prenotazioni"></a></div>
</div>
<?php
endif;
?>
</div><!-- .site-branding -->
</header><!-- #masthead -->
可以概括为
<header id="masthead" class="site-header">
<div class="site-branding">
<?php
if ( is_front_page() && is_home() ) :
?>
<div class="home_header">
</div>
<?php
else :
?>
<div class="page_header">
</div>
<?php
endif;
?>
</div><!-- .site-branding -->
</header><!-- #masthead -->
我在哪里犯了错误? 谢谢你!
I'm trying to have two different headers display for the homepage and for anything else.
I set in wordpress settings > reading : the homepage as a "static page" a page I pubblished named "Homepage".
My code should display the <div class="home_header"></div
in the homepage and <div class="page_header"></div>
in all other pages or posts.
The code doesn't seem to work and displays <div class="page_header"></div>
to all pages, Homepage included.
my code is
<header id="masthead" class="site-header">
<div class="site-branding">
<?php
if ( is_front_page() && is_home() ) :
?>
<div class="home_topbar">
<div class="contatti_sx">
<address>Via Indirizzo, 2, 00000 Paese RE</address><a href="tel:+393335554444">+39 333 555 4444</a>
</div>
<div class="socials">
<a href="https://www.facebook.com"><i></i></a>
<a href="https://www.instagram.com"><i></i></a>
</div>
<div class="language">
<a href="">IT</a><a href="">EN</a>
</div>
</div>
<div class="copertina">
<h4>EMILIA - La Bassa</h4>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<img src="<?php the_post_thumbnail() ?>" alt="">
</div>
<div class="menu_bar">
<div class="logo"><?php the_custom_logo(); ?></div>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'cdnonni' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
<div><a href="prenotazioni" class="prenotazioni"></a></div>
</div>
<?php
else :
?>
<div class="page_topbar">
<div class="contatti_sx">
<address>Via Indirizzo, 2, 00000 Paese RE</address><a href="tel:+393335554444">+39 333 555 4444</a>
</div>
<h1 class="topbar_title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<div class="socials">
<a href="https://www.facebook.com"><i></i></a>
<a href="https://www.instagram.com"><i></i></a>
</div>
<div class="language">
<a href="">IT</a><a href="">EN</a>
</div>
</div>
<div class="menu_bar">
<div class="logo"><?php the_custom_logo(); ?></div>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'cdnonni' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
<div><a href="prenotazioni" class="prenotazioni"></a></div>
</div>
<?php
endif;
?>
</div><!-- .site-branding -->
</header><!-- #masthead -->
which can be summarized to
<header id="masthead" class="site-header">
<div class="site-branding">
<?php
if ( is_front_page() && is_home() ) :
?>
<div class="home_header">
</div>
<?php
else :
?>
<div class="page_header">
</div>
<?php
endif;
?>
</div><!-- .site-branding -->
</header><!-- #masthead -->
where did I make a mistake?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论