Browse Source

feat: custom frontend page

pull/375/head
arzola 2 years ago
parent
commit
5d38b14be1
  1. 9
      assets/styles/layouts/_header.scss
  2. 2
      assets/styles/layouts/_page.scss
  3. 12
      dist/styles/aldine.css
  4. 6
      header.php
  5. 22
      inc/customizer/namespace.php
  6. 18
      inc/helpers/namespace.php

9
assets/styles/layouts/_header.scss

@ -24,8 +24,15 @@
margin-top: -540px; margin-top: -540px;
background: transparent; background: transparent;
&.custom-homepage {
margin-top: 0;
}
@media #{$breakpoint-large} { @media #{$breakpoint-large} {
margin-top: -880px; margin-top: -880px;
&.custom-homepage {
margin-top: 0;
}
} }
} }
@ -68,7 +75,7 @@
} }
} }
.page:not(.home) .header { .page .header {
height: rem(240); height: rem(240);
@media #{$breakpoint-large} { @media #{$breakpoint-large} {

2
assets/styles/layouts/_page.scss

@ -22,6 +22,6 @@ body {
} }
} }
.page.home:not(.has-sections) article { .page article {
margin-top: 0; margin-top: 0;
} }

12
dist/styles/aldine.css vendored

@ -2155,10 +2155,16 @@ input[type=submit] {
margin-top: -540px; margin-top: -540px;
background: transparent; background: transparent;
} }
.home #content.custom-homepage {
margin-top: 0;
}
@media screen and (min-width: 60rem) { @media screen and (min-width: 60rem) {
.home #content { .home #content {
margin-top: -880px; margin-top: -880px;
} }
.home #content.custom-homepage {
margin-top: 0;
}
} }
.home .entry-header { .home .entry-header {
@ -2208,11 +2214,11 @@ input[type=submit] {
} }
} }
.page:not(.home) .header { .page .header {
height: 15rem; height: 15rem;
} }
@media screen and (min-width: 60rem) { @media screen and (min-width: 60rem) {
.page:not(.home) .header { .page .header {
height: 55rem; height: 55rem;
} }
} }
@ -2282,7 +2288,7 @@ body #content a.call-to-action {
text-decoration: none; text-decoration: none;
} }
.page.home:not(.has-sections) article { .page article {
margin-top: 0; margin-top: 0;
} }

6
header.php

@ -9,6 +9,8 @@
* @package Aldine * @package Aldine
*/ */
use function Aldine\Helpers\custom_homepage;
?> ?>
<!doctype html> <!doctype html>
<html <?php language_attributes(); ?>> <html <?php language_attributes(); ?>>
@ -20,7 +22,7 @@
<?php wp_head(); ?> <?php wp_head(); ?>
</head> </head>
<body <?php body_class(); ?> data-barba="wrapper"> <body <?php body_class(); ?>>
<svg style="display: none;" xmlns="http://www.w3.org/2000/svg"> <svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
<defs> <defs>
<symbol id="icon-pressbooks" fill="currentColor" viewBox="0 0 45 44"> <symbol id="icon-pressbooks" fill="currentColor" viewBox="0 0 45 44">
@ -102,4 +104,4 @@
</div> </div>
</header> <!-- .header --> </header> <!-- .header -->
<div id="content" class="site-content clearfix"> <div id="content" class="site-content clearfix <?php echo custom_homepage(); ?>">

22
inc/customizer/namespace.php

@ -227,6 +227,28 @@ function customize_register( \WP_Customize_Manager $wp_customize ) {
] ]
); );
} }
$wp_customize->add_section(
'page_on_front', [
'title' => __( 'Front Page Settings', 'pressbooks-aldine' ),
'priority' => 24,
]
);
$wp_customize->add_setting(
'page_on_front', [
'type' => 'option',
'capability' => 'manage_options',
],
);
$wp_customize->add_control(
'page_on_front', [
'label' => __( 'Network Home Page', 'pressbooks-aldine' ),
'section' => 'page_on_front',
'type' => 'dropdown-pages',
]
);
} }
$wp_customize->add_section( $wp_customize->add_section(

18
inc/helpers/namespace.php

@ -334,7 +334,7 @@ function get_default_menu( $items = '' ) {
'SignOut' => 'sign-out', 'SignOut' => 'sign-out',
]; ];
$link = ( is_front_page() ) ? network_home_url( '#main' ) : network_home_url( '/' ); $link = network_home_url( '/' );
$items = sprintf( $items = sprintf(
'<li class="%3$s %3$s-%4$s"><a href="%1$s">%2$s</a></li>', '<li class="%3$s %3$s-%4$s"><a href="%1$s">%2$s</a></li>',
$link, $link,
@ -565,3 +565,19 @@ function get_catalog_page(): ?\WP_Post {
]); ]);
return $catalog_pages[0] ?? null; return $catalog_pages[0] ?? null;
} }
/**
* This function generate a class to know if the current page is a custom frontpage.
*
* @return string
*/
function custom_homepage(): string {
$home_page = get_option( 'page_on_front' );
if ( $home_page ) {
$template = get_page_template_slug( $home_page );
if ( 'page-catalog.php' === $template ) {
return 'custom-homepage';
}
}
return '';
}

Loading…
Cancel
Save