浏览代码

Try: Add hide site header/footer Customizer options to Varia.

Kjell Reigstad 4 年之前
父节点
当前提交
c6ff72af3e
共有 3 个文件被更改,包括 80 次插入2 次删除
  1. 24 0
      varia/inc/customize-preview-wpcom.js
  2. 12 2
      varia/inc/style-wpcom.css
  3. 44 0
      varia/inc/wpcom.php

+ 24 - 0
varia/inc/customize-preview-wpcom.js

@@ -18,4 +18,28 @@
 			}
 		} );
 	} );
+
+	// Hide Site Header
+	wp.customize( 'hide_site_header', function( value ) {
+		value.bind( function( to ) {
+			if ( true === to ) {
+				$( 'body' ).addClass( 'hide-homepage-header' );
+
+			} else {
+				$( 'body' ).removeClass( 'hide-homepage-header' );
+			}
+		} );
+	} );
+
+	// Hide Site Footer Menu
+	wp.customize( 'hide_site_footer', function( value ) {
+		value.bind( function( to ) {
+			if ( true === to ) {
+				$( 'body' ).addClass( 'hide-homepage-footer' );
+
+			} else {
+				$( 'body' ).removeClass( 'hide-homepage-footer' );
+			}
+		} );
+	} );
 } )( jQuery );

+ 12 - 2
varia/inc/style-wpcom.css

@@ -9,8 +9,18 @@
 	display: none;
 }
 
-.home.page.hide-homepage-title .site-main > article > .entry-content {
-	margin-top: 0;
+ /**
+ * Hide site header on the homepage
+ */
+.home.page.hide-homepage-header .site-header {
+	display: none;
+}
+
+ /**
+ * Hide footer navigation on the homepage
+ */
+.home.page.hide-homepage-footer .footer-navigation {
+	display: none;
 }
 
 /**

+ 44 - 0
varia/inc/wpcom.php

@@ -53,6 +53,38 @@ function varia_wpcom_customize_update( $wp_customize ) {
 		'settings'	  => 'hide_front_page_title',
 	) );
 
+	$wp_customize->add_setting( 'hide_site_header', array(
+		'default'              => false,
+		'type'                 => 'theme_mod',
+		'transport'            => 'postMessage',
+		'sanitize_callback'    => 'varia_sanitize_checkbox',
+	) );
+
+	$wp_customize->add_control( 'hide_site_header', array(
+		'label'		  => esc_html__( 'Hide the Site Header', 'varia' ),
+		'description' => esc_html__( 'Check to hide the site header, if your homepage is set to display a static page.', 'varia' ),
+		'section'	  => 'static_front_page',
+		'priority'	  => 10,
+		'type'		  => 'checkbox',
+		'settings'	  => 'hide_site_header',
+	) );
+
+	$wp_customize->add_setting( 'hide_site_footer', array(
+		'default'              => false,
+		'type'                 => 'theme_mod',
+		'transport'            => 'postMessage',
+		'sanitize_callback'    => 'varia_sanitize_checkbox',
+	) );
+
+	$wp_customize->add_control( 'hide_site_footer', array(
+		'label'		  => esc_html__( 'Hide the Site Footer Menu', 'varia' ),
+		'description' => esc_html__( 'Check to hide the site menu in the footer, if your homepage is set to display a static page.', 'varia' ),
+		'section'	  => 'static_front_page',
+		'priority'	  => 10,
+		'type'		  => 'checkbox',
+		'settings'	  => 'hide_site_footer',
+	) );
+
     $wp_customize->add_setting( 'color_a11y_warning' );
     $wp_customize->add_control( 'color_a11y_warning', array(
         'id'          => 'id',
@@ -115,6 +147,18 @@ function varia_wpcom_body_classes( $classes ) {
 		$classes[] = 'hide-homepage-title';
 	}
 
+	$hide_page_header = get_theme_mod( 'hide_page_header', false );
+
+	if ( true === $hide_page_header ) {
+		$classes[] = 'hide-homepage-header';
+	}
+
+	$hide_page_footer = get_theme_mod( 'hide_page_footer', false );
+
+	if ( true === $hide_page_footer ) {
+		$classes[] = 'hide-homepage-footer';
+	}
+
 	$credit_option = get_option( 'footercredit' );
 
 	if ( 'hidden' == $credit_option ) {