Browse Source

Merge pull request #375 from pressbooks/custom-frontpage

feat: custom frontend page
pull/378/head
Ricardo Aragon 2 years ago committed by GitHub
parent
commit
3f1e0e0494
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      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

11
assets/styles/layouts/_header.scss

@ -20,12 +20,19 @@
}
}
.home #content {
.home #content{
margin-top: -540px;
background: transparent;
&.custom-homepage {
margin-top: 0;
}
@media #{$breakpoint-large} {
margin-top: -880px;
&.custom-homepage {
margin-top: 0;
}
}
}
@ -68,7 +75,7 @@
}
}
.page:not(.home) .header {
.page .header {
height: rem(240);
@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;
}

12
dist/styles/aldine.css vendored

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

6
header.php

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

18
inc/helpers/namespace.php

@ -334,7 +334,7 @@ function get_default_menu( $items = '' ) {
'SignOut' => 'sign-out',
];
$link = ( is_front_page() ) ? network_home_url( '#main' ) : network_home_url( '/' );
$link = network_home_url( '/' );
$items = sprintf(
'<li class="%3$s %3$s-%4$s"><a href="%1$s">%2$s</a></li>',
$link,
@ -565,3 +565,19 @@ function get_catalog_page(): ?\WP_Post {
]);
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