Newer
Older
tonitalia-theme / template-parts / navigation / navigation-top.php
<?php
/**
 * Custom top navigation for single-page child theme.
 *
 * Wraps the primary menu inside a container toggled by an always-visible
 * hamburger button, on ogni dispositivo.
 */

$fixed_header = function_exists( 'tents_singlepage_get_fixed_header_settings' )
	? tents_singlepage_get_fixed_header_settings()
	: array( 'enabled' => false );

$facebook_url  = get_theme_mod( 'tents_social_facebook_url' );
$instagram_url = get_theme_mod( 'tents_social_instagram_url' );
$youtube_url   = get_theme_mod( 'tents_social_youtube_url' );
$has_social    = $facebook_url || $instagram_url || $youtube_url;

?>
<nav id="site-navigation" class="main-navigation singlepage-nav" aria-label="<?php esc_attr_e( 'Top Menu', 'twentyseventeen' ); ?>">
	<?php // Bottone originale del tema (necessario per la logica interna di sticky/navigation). ?>
	<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false">
		<?php
		if ( function_exists( 'twentyseventeen_get_svg' ) ) {
			echo twentyseventeen_get_svg( array( 'icon' => 'bars' ) );
			echo twentyseventeen_get_svg( array( 'icon' => 'close' ) );
		}
		_e( 'Menu', 'twentyseventeen' );
		?>
	</button>

	<?php if ( ! empty( $fixed_header['enabled'] ) ) : ?>
		<div class="tents-fixed-header" data-tents-fixed-header>
			<div class="tents-fixed-header__inner">
				<div class="tents-fixed-header__left">
					<?php if ( ! empty( $fixed_header['secondary_cta'] ) ) : ?>
						<a class="tents-fixed-header__cta tents-fixed-header__cta--secondary" href="<?php echo esc_url( $fixed_header['secondary_cta']['url'] ); ?>">
							<?php echo esc_html( $fixed_header['secondary_cta']['label'] ); ?>
						</a>
					<?php endif; ?>
				</div>

				<div class="tents-fixed-header__brand">
					<?php if ( ! empty( $fixed_header['logo_url'] ) ) : ?>
						<a class="tents-fixed-header__logo-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
							<img
								class="tents-fixed-header__logo"
								src="<?php echo esc_url( $fixed_header['logo_url'] ); ?>"
								alt="<?php echo esc_attr( $fixed_header['logo_alt'] ); ?>"
								decoding="async"
							/>
						</a>
					<?php else : ?>
						<a class="tents-fixed-header__site-title" href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
							<?php bloginfo( 'name' ); ?>
						</a>
					<?php endif; ?>
				</div>

				<div class="tents-fixed-header__right">
					<div class="tents-fixed-header__cta-row">
						<?php if ( ! empty( $fixed_header['primary_cta'] ) ) : ?>
							<a class="tents-fixed-header__cta tents-fixed-header__cta--primary" href="<?php echo esc_url( $fixed_header['primary_cta']['url'] ); ?>">
								<?php echo esc_html( $fixed_header['primary_cta']['label'] ); ?>
							</a>
						<?php endif; ?>
					</div>

					<?php if ( ! empty( $fixed_header['show_social'] ) && $has_social ) : ?>
						<div class="tents-fixed-header__actions">
							<div class="tents-fixed-header__social" aria-label="<?php esc_attr_e( 'Social links', 'tents-singlepage-child' ); ?>">
								<?php if ( ! empty( $fixed_header['social_label'] ) ) : ?>
									<span class="tents-fixed-header__social-label"><?php echo esc_html( $fixed_header['social_label'] ); ?></span>
								<?php endif; ?>

								<div class="tents-fixed-header__social-icons">
									<?php if ( $facebook_url ) : ?>
										<a href="<?php echo esc_url( $facebook_url ); ?>" target="_blank" rel="noopener noreferrer" class="singlepage-social-link singlepage-social-link--facebook" aria-label="<?php esc_attr_e( 'Facebook', 'tents-singlepage-child' ); ?>">
											<?php
											if ( function_exists( 'twentyseventeen_get_svg' ) ) {
												echo twentyseventeen_get_svg( array( 'icon' => 'facebook' ) );
											} else {
												echo '<span class="screen-reader-text">Facebook</span>';
											}
											?>
										</a>
									<?php endif; ?>

									<?php if ( $instagram_url ) : ?>
										<a href="<?php echo esc_url( $instagram_url ); ?>" target="_blank" rel="noopener noreferrer" class="singlepage-social-link singlepage-social-link--instagram" aria-label="<?php esc_attr_e( 'Instagram', 'tents-singlepage-child' ); ?>">
											<?php
											if ( function_exists( 'twentyseventeen_get_svg' ) ) {
												echo twentyseventeen_get_svg( array( 'icon' => 'instagram' ) );
											} else {
												echo '<span class="screen-reader-text">Instagram</span>';
											}
											?>
										</a>
									<?php endif; ?>

									<?php if ( $youtube_url ) : ?>
										<a href="<?php echo esc_url( $youtube_url ); ?>" target="_blank" rel="noopener noreferrer" class="singlepage-social-link singlepage-social-link--youtube" aria-label="<?php esc_attr_e( 'YouTube', 'tents-singlepage-child' ); ?>">
											<?php
											if ( function_exists( 'twentyseventeen_get_svg' ) ) {
												echo twentyseventeen_get_svg( array( 'icon' => 'youtube' ) );
											} else {
												echo '<span class="screen-reader-text">YouTube</span>';
											}
											?>
										</a>
									<?php endif; ?>
								</div>
							</div>
						</div>
					<?php endif; ?>
				</div>
			</div>
		</div>
	<?php else : ?>
		<?php // Bottone visibile sempre, che controlla l'apertura/chiusura del menu ad ancore. ?>
		<button class="singlepage-menu-toggle" aria-controls="top-menu" aria-expanded="false">
			<?php
			if ( function_exists( 'twentyseventeen_get_svg' ) ) {
				echo twentyseventeen_get_svg( array( 'icon' => 'bars' ) );
				echo twentyseventeen_get_svg( array( 'icon' => 'close' ) );
			}
			_e( 'Menu', 'twentyseventeen' );
			?>
		</button>
	<?php endif; ?>

	<div class="singlepage-menu-container" id="top-menu-container">
		<?php
		wp_nav_menu(
			array(
				'theme_location' => 'top',
				'menu_id'        => 'top-menu',
			)
		);
		?>

		<?php
		// Icone social dopo l'ultima voce di menĂ¹.
		if ( empty( $fixed_header['enabled'] ) && $has_social ) :
			?>
			<div class="singlepage-social-links" aria-label="<?php esc_attr_e( 'Social links', 'tents-singlepage-child' ); ?>">
				<?php if ( $facebook_url ) : ?>
					<a href="<?php echo esc_url( $facebook_url ); ?>" target="_blank" rel="noopener noreferrer" class="singlepage-social-link singlepage-social-link--facebook">
						<?php
						if ( function_exists( 'twentyseventeen_get_svg' ) ) {
							echo twentyseventeen_get_svg( array( 'icon' => 'facebook' ) );
						} else {
							echo '<span class="screen-reader-text">Facebook</span>';
						}
						?>
					</a>
				<?php endif; ?>

				<?php if ( $instagram_url ) : ?>
					<a href="<?php echo esc_url( $instagram_url ); ?>" target="_blank" rel="noopener noreferrer" class="singlepage-social-link singlepage-social-link--instagram">
						<?php
						if ( function_exists( 'twentyseventeen_get_svg' ) ) {
							echo twentyseventeen_get_svg( array( 'icon' => 'instagram' ) );
						} else {
							echo '<span class="screen-reader-text">Instagram</span>';
						}
						?>
					</a>
				<?php endif; ?>

				<?php if ( $youtube_url ) : ?>
					<a href="<?php echo esc_url( $youtube_url ); ?>" target="_blank" rel="noopener noreferrer" class="singlepage-social-link singlepage-social-link--youtube">
						<?php
						if ( function_exists( 'twentyseventeen_get_svg' ) ) {
							echo twentyseventeen_get_svg( array( 'icon' => 'youtube' ) );
						} else {
							echo '<span class="screen-reader-text">YouTube</span>';
						}
						?>
					</a>
				<?php endif; ?>
			</div>
		<?php endif; ?>
	</div>
</nav><!-- #site-navigation -->