更新时间:2023-12-01 22:45:22
我想到的方法很少.
1) 对主页和其他页面使用单独的 header.php 模板.
1) Using separate header.php template for home page and other page .
2) 使用菜单位置设置.
2) Using menu location settings .
3) 使用设置选项并根据它们显示菜单
3) Using setting options and according to them display the menu
但是我认为你的代码应该尝试用
But with your code I think you should try replace is_page_template('template-parts/page-homepage.php')
with
is_page_template('page-homepage.php')
作为
is_page_template() 不适用于目录
is_page_template() is not going for directory .
function is_page_template( $template = '' ) {
if ( ! is_page() )
return false;
$page_template = get_page_template_slug( get_queried_object_id() );
if ( empty( $template ) )
return (bool) $page_template;
if ( $template == $page_template )
return true;
if ( is_array( $template ) ) {
if ( ( in_array( 'default', $template, true ) && ! $page_template )
|| in_array( $page_template, $template, true )
) {
return true;
}
}
return ( 'default' === $template && ! $page_template );
}
2 ) 当使用菜单位置设置时,您可以使用
2 ) When using menu location setting you can use
register_nav_menus( array(
'pluginbuddy_mobile' => 'PluginBuddy Mobile Navigation Menu',
'footer_menu' => 'My Custom Footer Menu',
) );
和
<?php
if ( has_nav_menu( 'footer_menu' ) ) {
wp_nav_menu( array( 'theme_location' => 'footer_menu' ) );
} ?>
控制菜单的显示.
3) 通过设置选项,您可以使用 update_option()
和 get_option()
做一些事情.
3) With setting options you can do something use update_option()
and get_option()
.