ソースを参照

refactor seedlet and blank canvas so they share more code

Ben Dwyer 4 年 前
コミット
0f8718a58c

+ 0 - 55
blank-canvas/header.php

@@ -1,55 +0,0 @@
-<?php
-/**
- * The header for our theme
- *
- * This is the template that displays all of the <head> section and everything up until <div id="content">
- *
- * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
- *
- * @package Blank Canvas
- * @since 1.0
- */
-$blog_info    = get_bloginfo( 'name' );
-$description  = get_bloginfo( 'description', 'display' );
-$show_title   = ( true === get_theme_mod( 'display_title_and_tagline', true ) );
-$header_class = $show_title ? 'site-title' : 'screen-reader-text';
-
-?><!doctype html>
-<html <?php language_attributes(); ?>>
-<head>
-	<meta charset="<?php bloginfo( 'charset' ); ?>" />
-	<meta name="viewport" content="width=device-width, initial-scale=1" />
-	<link rel="profile" href="https://gmpg.org/xfn/11" />
-	<?php wp_head(); ?>
-</head>
-
-<body <?php body_class(); ?>>
-<?php wp_body_open(); ?>
-<div id="page" class="site">
-	<a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'blank-canvas' ); ?></a>
-
-	<?php if ( ! is_singular() ) : ?>
-		<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
-			<?php if ( has_custom_logo() && $show_title ) : ?>
-				<div class="site-logo"><?php the_custom_logo(); ?></div>
-			<?php endif; ?>
-
-			<div class="site-branding">
-				<?php if ( ! empty( $blog_info ) && $show_title ) : ?>
-					<?php if ( is_front_page() && is_home() ) : ?>
-						<h1 class="<?php echo esc_attr( $header_class ); ?>"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php echo $blog_info; ?></a></h1>
-					<?php else : ?>
-						<p class="<?php echo esc_attr( $header_class ); ?>"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php echo $blog_info; ?></a></p>
-					<?php endif; ?>
-				<?php endif; ?>
-
-				<?php if ( ( $description || is_customize_preview() ) && $show_title ) : ?>
-					<p class="site-description">
-						<?php echo $description; ?>
-					</p>
-				<?php endif; ?>
-			</div><!-- .site-branding -->
-		</header><!-- #masthead -->
-	<?php endif; ?>
-
-	<div id="content" class="site-content">

+ 10 - 0
blank-canvas/template-parts/header/header-content.php

@@ -0,0 +1,10 @@
+<?php
+	$show_title   = ( true === get_theme_mod( 'display_title_and_tagline', true ) );
+	$header_class = $show_title ? 'site-title' : 'screen-reader-text';
+?>
+
+<?php if ( ! is_singular() ) : ?>
+	<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
+		<?php get_template_part( 'template-parts/header/site-branding' ); ?>
+	</header><!-- #masthead -->
+<?php endif; ?>

+ 1 - 100
seedlet/header.php

@@ -9,11 +9,6 @@
  * @package Seedlet
  * @since 1.0.0
  */
-$has_primary_nav = has_nav_menu( 'primary' );
-$header_classes  = 'site-header header_classes';
-$header_classes .= has_custom_logo() ? ' has-logo' : '';
-$header_classes .= true === get_theme_mod( 'display_title_and_tagline', true ) ? ' has-title-and-tagline' : '';
-$header_classes .= $has_primary_nav ? ' has-menu' : '';
 ?><!doctype html>
 <html <?php language_attributes(); ?>>
 <head>
@@ -28,100 +23,6 @@ $header_classes .= $has_primary_nav ? ' has-menu' : '';
 <div id="page" class="site">
 	<a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'seedlet' ); ?></a>
 
-	<?php if ( false === get_theme_mod( 'hide_site_header', false ) ) : ?>
-		<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
-			<?php get_template_part( 'template-parts/header/site-branding' ); ?>
-
-			<?php if ( $has_primary_nav ) : ?>
-				<nav id="site-navigation" class="primary-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Main', 'seedlet' ); ?>">
-					<button id="primary-close-menu" class="button close">
-						<span class="dropdown-icon close"><?php _e( 'Close', 'seedlet' ); ?> <?php echo seedlet_get_icon_svg( 'close' ); ?></span>
-						<span class="hide-visually collapsed-text"><?php _e( 'collapsed', 'seedlet' ); ?></span>
-					</button>
-					<?php
-					// Get menu slug
-					$location_name = 'primary';
-					$locations     = get_nav_menu_locations();
-					$menu_id       = $locations[ $location_name ];
-					$menu_obj      = wp_get_nav_menu_object( $menu_id );
-
-					wp_nav_menu(
-						array(
-							'theme_location'  => 'primary',
-							'menu_class'      => 'menu-wrapper',
-							'container_class' => 'primary-menu-container',
-							'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
-						)
-					);
-					?>
-				</nav><!-- #site-navigation -->
-			<?php endif; ?>
-
-			<div class="menu-button-container">
-				<?php if ( $has_primary_nav ) : ?>
-					<button id="primary-open-menu" class="button open">
-						<span class="dropdown-icon open"><?php _e( 'Menu', 'seedlet' ); ?> <?php echo seedlet_get_icon_svg( 'menu' ); ?></span>
-						<span class="hide-visually expanded-text"><?php _e( 'expanded', 'seedlet' ); ?></span>
-					</button>
-				<?php endif; ?>
-			</div>
-
-			<?php if ( class_exists( 'WooCommerce' ) ) : ?>
-				<nav class="woo-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Woo Minicart', 'seedlet' ); ?>">
-					<?php
-					echo( sprintf(
-						'<button id="woo-close-menu" class="button close">
-							<span class="dropdown-icon close">%1$s %2$s</span>
-							<span class="hide-visually collapsed-text">%3$s</span>
-						</button>
-						<div class="woocommerce-menu-container">
-							<ul id="woocommerce-menu" class="menu-wrapper"">
-							<li class="menu-item woocommerce-menu-item %4$s" title="%5$s">
-								%6$s
-								<ul class="sub-menu">
-									<li class="woocommerce-cart-widget" title="%7$s">
-										%8$s
-									</li>
-								</ul>
-							</li>',
-						esc_html__( 'Close', 'seedlet' ),
-						seedlet_get_icon_svg( 'close' ),
-						esc_html__( 'collapsed', 'seedlet' ),
-						is_cart() ? 'current-menu-item' : '',
-						esc_attr__( 'View your shopping cart', 'seedlet' ),
-						seedlet_cart_link(),
-						esc_attr__( 'View your shopping list', 'seedlet' ),
-						seedlet_cart_widget()
-					) );
-					?>
-				</nav><!-- .woo-navigation -->
-			<?php endif; ?>
-
-			<div class="menu-button-container">
-				<?php if ( class_exists( 'WooCommerce' ) ) : ?>
-					<button id="woo-open-menu" class="button open">
-						<span class="dropdown-icon open"><?php echo seedlet_get_icon_svg( 'shopping_cart' ); ?> <?php _e( 'Cart', 'seedlet' ); ?></span>
-						<span class="hide-visually expanded-text"><?php esc_html__( 'expanded', 'seedlet' ); ?></span>
-					</button>
-				<?php endif; ?>
-			</div>
-
-			<?php if ( has_nav_menu( 'social' ) ) : ?>
-				<nav class="social-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Social Links Menu', 'seedlet' ); ?>">
-					<?php
-					wp_nav_menu(
-						array(
-							'theme_location' => 'social',
-							'link_before'    => '<span class="screen-reader-text">',
-							'link_after'     => '</span>' . seedlet_get_icon_svg( 'link' ),
-							'depth'          => 1,
-						)
-					);
-					?>
-				</nav><!-- .social-navigation -->
-			<?php endif; ?>
-
-		</header><!-- #masthead -->
-	<?php endif; ?>
+	<?php get_template_part( 'template-parts/header/header-content' ); ?>
 
 	<div id="content" class="site-content">

+ 14 - 0
seedlet/template-parts/header/header-content.php

@@ -0,0 +1,14 @@
+<?php
+$has_primary_nav = has_nav_menu( 'primary' );
+$header_classes  = 'site-header header_classes';
+$header_classes .= has_custom_logo() ? ' has-logo' : '';
+$header_classes .= true === get_theme_mod( 'display_title_and_tagline', true ) ? ' has-title-and-tagline' : '';
+$header_classes .= $has_primary_nav ? ' has-menu' : '';
+?>
+
+<?php if ( false === get_theme_mod( 'hide_site_header', false ) ) : ?>
+	<header id="masthead" class="<?php echo $header_classes; ?>" role="banner">
+		<?php get_template_part( 'template-parts/header/site-branding' ); ?>
+		<?php get_template_part( 'template-parts/header/navigation' ); ?>
+	</header><!-- #masthead -->
+<?php endif; ?>

+ 91 - 0
seedlet/template-parts/header/navigation.php

@@ -0,0 +1,91 @@
+<?php
+	$has_primary_nav = has_nav_menu( 'primary' );
+?>
+<?php if ( $has_primary_nav ) : ?>
+	<nav id="site-navigation" class="primary-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Main', 'seedlet' ); ?>">
+		<button id="primary-close-menu" class="button close">
+			<span class="dropdown-icon close"><?php _e( 'Close', 'seedlet' ); ?> <?php echo seedlet_get_icon_svg( 'close' ); ?></span>
+			<span class="hide-visually collapsed-text"><?php _e( 'collapsed', 'seedlet' ); ?></span>
+		</button>
+		<?php
+		// Get menu slug
+		$location_name = 'primary';
+		$locations     = get_nav_menu_locations();
+		$menu_id       = $locations[ $location_name ];
+		$menu_obj      = wp_get_nav_menu_object( $menu_id );
+
+		wp_nav_menu(
+			array(
+				'theme_location'  => 'primary',
+				'menu_class'      => 'menu-wrapper',
+				'container_class' => 'primary-menu-container',
+				'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
+			)
+		);
+		?>
+	</nav><!-- #site-navigation -->
+<?php endif; ?>
+
+<div class="menu-button-container">
+	<?php if ( $has_primary_nav ) : ?>
+		<button id="primary-open-menu" class="button open">
+			<span class="dropdown-icon open"><?php _e( 'Menu', 'seedlet' ); ?> <?php echo seedlet_get_icon_svg( 'menu' ); ?></span>
+			<span class="hide-visually expanded-text"><?php _e( 'expanded', 'seedlet' ); ?></span>
+		</button>
+	<?php endif; ?>
+</div>
+
+<?php if ( class_exists( 'WooCommerce' ) ) : ?>
+	<nav class="woo-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Woo Minicart', 'seedlet' ); ?>">
+		<?php
+		echo( sprintf(
+			'<button id="woo-close-menu" class="button close">
+				<span class="dropdown-icon close">%1$s %2$s</span>
+				<span class="hide-visually collapsed-text">%3$s</span>
+			</button>
+			<div class="woocommerce-menu-container">
+				<ul id="woocommerce-menu" class="menu-wrapper"">
+				<li class="menu-item woocommerce-menu-item %4$s" title="%5$s">
+					%6$s
+					<ul class="sub-menu">
+						<li class="woocommerce-cart-widget" title="%7$s">
+							%8$s
+						</li>
+					</ul>
+				</li>',
+			esc_html__( 'Close', 'seedlet' ),
+			seedlet_get_icon_svg( 'close' ),
+			esc_html__( 'collapsed', 'seedlet' ),
+			is_cart() ? 'current-menu-item' : '',
+			esc_attr__( 'View your shopping cart', 'seedlet' ),
+			seedlet_cart_link(),
+			esc_attr__( 'View your shopping list', 'seedlet' ),
+			seedlet_cart_widget()
+		) );
+		?>
+	</nav><!-- .woo-navigation -->
+<?php endif; ?>
+
+<div class="menu-button-container">
+	<?php if ( class_exists( 'WooCommerce' ) ) : ?>
+		<button id="woo-open-menu" class="button open">
+			<span class="dropdown-icon open"><?php echo seedlet_get_icon_svg( 'shopping_cart' ); ?> <?php _e( 'Cart', 'seedlet' ); ?></span>
+			<span class="hide-visually expanded-text"><?php esc_html__( 'expanded', 'seedlet' ); ?></span>
+		</button>
+	<?php endif; ?>
+</div>
+
+<?php if ( has_nav_menu( 'social' ) ) : ?>
+	<nav class="social-navigation" role="navigation" aria-label="<?php esc_attr_e( 'Social Links Menu', 'seedlet' ); ?>">
+		<?php
+		wp_nav_menu(
+			array(
+				'theme_location' => 'social',
+				'link_before'    => '<span class="screen-reader-text">',
+				'link_after'     => '</span>' . seedlet_get_icon_svg( 'link' ),
+				'depth'          => 1,
+			)
+		);
+		?>
+	</nav><!-- .social-navigation -->
+<?php endif; ?>