Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Adds dynamic header and footer in WordPress theme. #36

Merged
merged 25 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1c771d5
Issue 33 Add WordPress menus.
kopepasah Jan 19, 2018
f5302b0
Issue 33 Filter custom styles and removes unnecessary styles.
kopepasah Jan 19, 2018
7b9d415
33 Add custom component scripts.
kopepasah Jan 21, 2018
6f30f4c
33 Add dynamic header markup.
kopepasah Jan 21, 2018
f83df11
33 Only add search form in header menu.
kopepasah Jan 21, 2018
bf86b63
33 Add dynamic site footer.
kopepasah Jan 21, 2018
a9f3f03
33 Fix 🐛, header centered alignment.
kopepasah Jan 21, 2018
b219f8d
33 Fix 🐛, improve search input text.
kopepasah Jan 21, 2018
61b15ec
33 Fix , header font size and margin.
kopepasah Jan 21, 2018
a0ddd2c
33 Build Assets.
kopepasah Jan 21, 2018
efaf106
33 Print copyright.
kopepasah Jan 22, 2018
f50c801
33 Fix typo and adjust comment.
kopepasah Jan 22, 2018
66c2405
33 Add @todo as a reminder this will be removed.
kopepasah Jan 22, 2018
0416daf
33 Remove unused enqueue scripts function.
kopepasah Jan 22, 2018
f56cac2
33 Adjust comment for menu hook.
kopepasah Jan 22, 2018
d3bdd34
Merge branch 'develop' into add/33
kopepasah Jan 22, 2018
3f6f1cd
33 Edit nav menu comment.
kopepasah Jan 23, 2018
82de045
33 Implement custom search form template.
kopepasah Jan 23, 2018
b83a900
33 Enqueue styles the standard WordPress way.
kopepasah Jan 23, 2018
2458e1f
Fix style sheet path
ThierryA Jan 23, 2018
efd1f6f
Move form outside the menu
ThierryA Jan 23, 2018
bbcb3a5
Use WP default translation where possible
ThierryA Jan 23, 2018
327d88b
Improve header styling
ThierryA Jan 23, 2018
9e0045e
Adjusted static file header according to the latest BE changes
ThierryA Jan 23, 2018
5dd214d
Merge branch 'develop' into add/33
ThierryA Jan 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/dist/css/main.css

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions assets/html/templates/site-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
<li class="menu-item"><a href="category.php#development=1">Gaming</a></li>
<li class="menu-item"><a href="category.php#development=1">Shopping</a></li>
<li class="menu-item menu-item-search-form">
<form method="GET" action="https://example.com/search" target="_top">
<input type="search" placeholder="Search">
<button name="submit"></button>
</form>
</li>
</ul>
<div class="wrap__item--search">
<form method="GET" action="https://example.com/search" target="_top">
<input type="search" placeholder="Search">
<button name="submit"></button>
</form>
</div>
</nav>
</header>
3 changes: 3 additions & 0 deletions assets/src/css/elements/_search-icon.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//
// Search Submit Button Icon
//
// Dev Note: used on the <button> element.
//
%search-icon {
font-size: 0;
position: relative;
background: $black;
border: 2px solid $white;
Expand Down
23 changes: 12 additions & 11 deletions assets/src/css/modules/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

&--header &__item--branding {
position: relative;
margin-left: auto;
margin-right: auto;

@media ( query( max, tablet ) ) {
background: $black;
Expand All @@ -61,6 +63,9 @@
}

&-title {
font-size: 56px;
font-weight: 700;
margin: 32px 0 0;

a {
color: $white;
Expand Down Expand Up @@ -149,15 +154,9 @@
}

@media ( query( min, tablet ) ) {
display: block;
flex-basis: 100%;
order: 1;

.container {
display: flex;
justify-content: space-between;
align-items: center;
}
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
}

.menu-item-has-children {
Expand All @@ -168,8 +167,7 @@
}
}

.menu-item-search-form {
float: right;
.wrap__item--search {
margin-top: -4px;
margin-bottom: -4px;

Expand All @@ -180,9 +178,12 @@
font-size: 14px;
max-width: 70px;
transition: max-width 100ms linear, background-color 100ms linear;
color: $white;
text-overflow: ellipsis;

&:focus {
background-color: $white;
color: $black;
max-width: 200px;
}

Expand Down
36 changes: 17 additions & 19 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@
/**
* The template for displaying the footer
*
* Contains the closing of the #content div and all content after.
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package AMPConf
*/

?>

</div><!-- #content -->
<footer class="wrap wrap--full-width wrap--footer">
<nav class="wrap__item wrap__item--footer-menu">
<?php
wp_nav_menu(
array(
'theme_location' => 'footer',
'menu_id' => false,
'depth' => 1,
)
);
?>
</nav>

<footer id="colophon" class="site-footer">
<div class="site-info">
<a href="<?php echo esc_url( __( 'https://wordpress.org/', 'ampconf' ) ); ?>">
<?php
/* translators: %s: CMS name, i.e. WordPress. */
printf( esc_html__( 'Proudly powered by %s', 'ampconf' ), 'WordPress' );
?>
</a>
<span class="sep"> | </span>
<?php
/* translators: 1: Theme name, 2: Theme author. */
printf( esc_html__( 'Theme: %1$s by %2$s.', 'ampconf' ), 'ampconf', '<a href="http://underscores.me/">Me</a>' );
?>
</div><!-- .site-info -->
</footer><!-- #colophon -->
</div><!-- #page -->
<p class="wrap__item wrap__item--footer-copyright">
<?php printf( '&copy; %s', esc_html( date( 'Y' ) ) ); ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
</p>
</footer>

<?php wp_footer(); ?>

Expand Down
32 changes: 23 additions & 9 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ function ampconf_setup() {
*/
add_theme_support( 'post-thumbnails' );

// This theme uses wp_nav_menu() in one location.
// This theme uses wp_nav_menu() in multiple locations.
register_nav_menus(
array(
'menu-1' => esc_html__( 'Primary', 'ampconf' ),
'header' => esc_html__( 'Header', 'ampconf' ),
'footer' => esc_html__( 'Footer', 'ampconf' ),
)
);

Expand Down Expand Up @@ -130,16 +131,29 @@ function ampconf_widgets_init() {
add_action( 'widgets_init', 'ampconf_widgets_init' );

/**
* Enqueue scripts and styles.
* Adds custom component scripts to the document.
*
* @todo Remove once amp-wp plugin automatically includes component scripts.
*
* @param array $amp_scripts AMP Component scripts, mapping component names to component source URLs.
*
* @return array
*/
function ampconf_scripts() {
wp_enqueue_style( 'ampconf-style', get_stylesheet_uri() );
function ampconf_amp_component_scripts( $amp_scripts ) {
$amp_scripts['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js';
$amp_scripts['amp-bind'] = 'https://cdn.ampproject.org/v0/amp-bind-0.1.js';

if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
return $amp_scripts;
}
add_filter( 'amp_component_scripts', 'ampconf_amp_component_scripts' );

/**
* Enqueues styles.
*/
function ampconf_enqueue_styles() {
wp_enqueue_style( 'ampconf', get_template_directory_uri() . '/assets/dist/css/main.css' );
}
add_action( 'wp_enqueue_scripts', 'ampconf_scripts' );
add_action( 'wp_enqueue_scripts', 'ampconf_enqueue_styles' );

/**
* Implement the Custom Header feature.
Expand Down
42 changes: 23 additions & 19 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @package AMPConf
*/

$description = get_bloginfo( 'description', 'display' );
?>
<!doctype html>
<html amp <?php language_attributes(); ?>>
Expand All @@ -18,35 +19,38 @@
</head>

<body <?php body_class(); ?>>
<div id="page" class="site">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'ampconf' ); ?></a>

<header id="masthead" class="site-header">
<div class="site-branding">
<?php the_custom_logo(); ?>
<?php if ( is_front_page() && is_home() ) : ?>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<?php else : ?>
<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
<?php endif; ?>
<header class="wrap wrap--header wrap--header__menu-hidden" [class]="mobileMenu ? 'wrap wrap--header' : 'wrap wrap--header wrap--header__menu-hidden'">

<div class="wrap__item wrap__item--branding">
<<?php ampconf_branding_tag(); ?> class="wrap__item--branding-title">
<?php if ( has_custom_logo() ) : ?>
<?php the_custom_logo(); ?>
<?php else : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
<?php endif; ?>
</<?php ampconf_branding_tag(); ?>>

<?php $description = get_bloginfo( 'description', 'display' ); ?>
<?php if ( $description || is_customize_preview() ) : ?>
<p class="site-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
<p class="wrap__item--branding-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
<?php endif; ?>
</div><!-- .site-branding -->

<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'ampconf' ); ?></button>
<button class="wrap__item--menu-toggle" on="tap:AMP.setState( { mobileMenu: ! mobileMenu } )" aria-controls="primary-menu" aria-expanded="false"></button>
</div>

<nav class="wrap__item wrap__item--menu">
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
'theme_location' => 'header',
'menu_id' => false,
)
);
?>
</nav><!-- #site-navigation -->
</header><!-- #masthead -->

<div id="content" class="site-content">
<div class="wrap__item--search">
<?php get_search_form(); ?>
</div>
</nav>
</header>
9 changes: 9 additions & 0 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ function ampconf_post_thumbnail() {
endif; // End is_singular().
}
endif;

if ( ! function_exists( 'ampconf_branding_tag' ) ) :
/**
* Outputs the branding in header as h1 or p, depending on the current view.
*/
function ampconf_branding_tag() {
echo esc_html( ( is_front_page() && is_home() ) ? 'h1' : 'p' );
}
endif;
Loading