The more intended WP way but with a lot of shortcodes, will change to Gutenberg

This commit is contained in:
2026-09-06 00:14:07 +02:00
parent 4d8a7a6924
commit f8ff394db2
12 changed files with 337 additions and 839 deletions
@@ -1,13 +1,17 @@
<?php
/**
* HogelandLinux theme functions and definitions.
*
* A universal classic theme: page content lives in the editor (Gutenberg /
* classic editor), pages show up in the menu automatically, and the original
* site's design system is exposed through shortcodes for easy composition.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'HOGELANDLINUX_VERSION', '1.0.0' );
define( 'HOGELANDLINUX_VERSION', '1.0.1' );
define( 'HOGELANDLINUX_URL', get_template_directory_uri() );
define( 'HOGELANDLINUX_PATH', get_template_directory() );
@@ -64,65 +68,314 @@ function hogelandlinux_scripts() {
add_action( 'wp_enqueue_scripts', 'hogelandlinux_scripts' );
/**
* Helper: current page name, used to highlight the active nav item.
*/
function hogelandlinux_current_page() {
if ( is_front_page() ) {
return 'home';
}
$page = get_queried_object();
if ( $page && isset( $page->post_name ) ) {
$name = $page->post_name;
} else {
$name = wp_basename( (string) wp_parse_url( home_url( $GLOBALS['wp']->request ?? '' ), PHP_URL_PATH ) );
}
return $name ? $name : 'home';
}
/**
* Render a nav link with the active class applied.
*/
function hogelandlinux_nav_link( $label, $path, $key ) {
$current = hogelandlinux_current_page();
$class = ( $current === $key ) ? ' class="active"' : '';
printf( '<a href="%s"%s>%s</a>', esc_url( home_url( $path ) ), $class, esc_html( $label ) );
}
/**
* Business info used across the template (matches the original static site).
* Business info used across the site (matches the original static site).
* All values can be overridden on the Settings > General screen.
*/
function hogelandlinux_business() {
return array(
'name' => get_bloginfo( 'name' ),
'kvk' => '91927935',
'email' => 'info@chemistry.software',
'street' => 'Voorstraat 123',
'postal' => '9967 AA',
'village' => 'Eenrum',
'kvk' => get_option( 'hl_kvk', '91927935' ),
'email' => get_option( 'hl_email', get_option( 'admin_email', 'info@chemistry.software' ) ),
'street' => get_option( 'hl_street', 'Voorstraat 123' ),
'postal' => get_option( 'hl_postal', '9967 AA' ),
'village' => get_option( 'hl_village', 'Eenrum' ),
'domain' => wp_parse_url( home_url(), PHP_URL_HOST ),
'about' => 'Bdnugget',
'birth' => '1990-01-01',
'son_birth' => '2022-01-01',
);
}
/**
* Age helper, mirrors the Go site's age calculation.
* Determine which page slug should be considered "active route" for the menu.
*/
function hogelandlinux_age( $birth ) {
$birth = DateTime::createFromFormat( 'Y-m-d', $birth );
if ( ! $birth ) {
return 0;
function hogelandlinux_current_key() {
if ( is_front_page() ) {
return 'home';
}
$now = new DateTime();
$age = $now->diff( $birth )->y;
return $age;
if ( is_home() ) {
return 'blog';
}
$obj = get_queried_object();
if ( $obj && isset( $obj->post_name ) ) {
return $obj->post_name;
}
return home_url();
}
/**
* Excerpt size for pages used on the front page.
* Render the primary nav. Uses a registered WordPress menu when one is set,
* otherwise falls back to listing published top-level pages (so any new page
* automatically appears in the menu).
*/
function hogelandlinux_excerpt_length( $length ) {
return 20;
function hogelandlinux_nav( $location = 'primary' ) {
$locations = get_nav_menu_locations();
if ( ! empty( $locations[ $location ] ) ) {
wp_nav_menu(
array(
'theme_location' => $location,
'container' => false,
'menu_class' => 'nav-links',
'items_wrap' => '<ul class="nav-links">%3$s</ul>',
'fallback_cb' => false,
)
);
return;
}
if ( 'footer' === $location ) {
return;
}
// Fallback: list pages automatically.
$pages = get_pages(
array(
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'exclude' => get_option( 'page_on_front' ) ? array( (int) get_option( 'page_on_front' ) ) : array(),
)
);
if ( empty( $pages ) ) {
return;
}
echo '<ul class="nav-links">';
foreach ( $pages as $page ) {
$current = ( hogelandlinux_current_key() === $page->post_name ) ? ' active' : '';
printf(
'<li class="menu-item%s"><a href="%s">%s</a></li>',
esc_attr( $current ),
esc_url( get_permalink( $page ) ),
esc_html( get_the_title( $page ) )
);
}
echo '</ul>';
}
add_filter( 'excerpt_length', 'hogelandlinux_excerpt_length' );
/**
* Fallback for the mobile menu: same pages as primary, or registered menu.
*/
function hogelandlinux_nav_mobile() {
$locations = get_nav_menu_locations();
if ( ! empty( $locations['primary'] ) ) {
wp_nav_menu(
array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => '',
'items_wrap' => '%3$s',
'fallback_cb' => false,
)
);
return;
}
$pages = get_pages(
array(
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'exclude' => get_option( 'page_on_front' ) ? array( (int) get_option( 'page_on_front' ) ) : array(),
)
);
if ( empty( $pages ) ) {
return;
}
foreach ( $pages as $page ) {
$current = ( hogelandlinux_current_key() === $page->post_name ) ? ' active' : '';
printf(
'<a href="%s" class="%s">%s</a>',
esc_url( get_permalink( $page ) ),
esc_attr( trim( $current ) ),
esc_html( get_the_title( $page ) )
);
}
}
/**
* Shortcode: a generic hero banner.
*
* [hero title="..." subtitle="..." button_text="..." button_url="..."]
* [hero button_secondary_text="..." button_secondary_url="..."]
*/
function hogelandlinux_shortcode_hero( $atts ) {
$atts = shortcode_atts(
array(
'title' => '',
'subtitle' => '',
'button_text' => '',
'button_url' => '',
'button2_text' => '',
'button2_url' => '',
'large' => 'no',
),
$atts,
'hero'
);
ob_start();
?>
<section class="<?php echo ( 'yes' === $atts['large'] ) ? 'hero' : 'page-hero'; ?>">
<div class="<?php echo ( 'yes' === $atts['large'] ) ? 'hero-content' : 'container'; ?>">
<?php if ( $atts['title'] ) : ?>
<h1><?php echo esc_html( $atts['title'] ); ?></h1>
<?php endif; ?>
<?php if ( $atts['subtitle'] ) : ?>
<p class="hero-subtitle"><?php echo esc_html( $atts['subtitle'] ); ?></p>
<?php endif; ?>
<?php if ( $atts['button_text'] ) : ?>
<div class="hero-buttons">
<a href="<?php echo esc_url( $atts['button_url'] ); ?>" class="btn btn-primary"><?php echo esc_html( $atts['button_text'] ); ?></a>
<?php if ( $atts['button2_text'] ) : ?>
<a href="<?php echo esc_url( $atts['button2_url'] ); ?>" class="btn btn-secondary"><?php echo esc_html( $atts['button2_text'] ); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</section>
<?php
return ob_get_clean();
}
add_shortcode( 'hero', 'hogelandlinux_shortcode_hero' );
/**
* Shortcode: opening of a section with an optional title.
* [section title="..."] ... [end-section]
* Use with optional class attr: [section title="..." class="section--brand"]
*/
function hogelandlinux_shortcode_section( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'title' => '',
'class' => 'section--light',
),
$atts,
'section'
);
$title = $atts['title'] ? '<h2>' . esc_html( $atts['title'] ) . '</h2>' : '';
return '<section class="section ' . esc_attr( $atts['class'] ) . '"><div class="container">' . $title . do_shortcode( $content ) . '</div></section>';
}
add_shortcode( 'section', 'hogelandlinux_shortcode_section' );
/**
* Shortcode: a single card.
* [card title="..." class="card--benefit" icon="🛡️"]Body content[/card]
*/
function hogelandlinux_shortcode_card( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'title' => '',
'class' => 'card--service',
'icon' => '',
'link' => '',
),
$atts,
'card'
);
$inner = '';
if ( $atts['icon'] ) {
$inner .= '<div class="card__icon">' . $atts['icon'] . '</div>';
}
if ( $atts['title'] ) {
$inner .= '<h3>' . esc_html( $atts['title'] ) . '</h3>';
}
$inner .= do_shortcode( $content );
$class = 'card ' . esc_attr( $atts['class'] );
if ( $atts['link'] ) {
return '<a class="' . esc_attr( $class . ' card-link' ) . '" href="' . esc_url( $atts['link'] ) . '">' . $inner . '</a>';
}
return '<div class="' . esc_attr( $class ) . '">' . $inner . '</div>';
}
add_shortcode( 'card', 'hogelandlinux_shortcode_card' );
/**
* Shortcode: a responsive grid.
* [grid cols="benefits|services|distros|2|3"] content [/grid]
*/
function hogelandlinux_shortcode_grid( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'cols' => 'services',
),
$atts,
'grid'
);
$map = array(
'benefits' => 'benefits-grid',
'services' => 'services-grid',
'distros' => 'distros-grid',
'features' => 'features-grid',
'steps' => 'steps-grid',
'2' => 'grid grid--2-col',
'3' => 'grid grid--3-col',
);
$class = isset( $map[ $atts['cols'] ] ) ? $map[ $atts['cols'] ] : 'grid';
return '<div class="' . esc_attr( $class ) . '">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'grid', 'hogelandlinux_shortcode_grid' );
/**
* Shortcode: a call-to-action section.
* [cta title="..." text="..." button_text="..." button_url="..."]
*/
function hogelandlinux_shortcode_cta( $atts ) {
$atts = shortcode_atts(
array(
'title' => '',
'text' => '',
'button_text' => '',
'button_url' => '',
),
$atts,
'cta'
);
ob_start();
?>
<section class="section cta">
<div class="container">
<h2><?php echo esc_html( $atts['title'] ); ?></h2>
<p><?php echo esc_html( $atts['text'] ); ?></p>
<?php if ( $atts['button_text'] ) : ?>
<a href="<?php echo esc_url( $atts['button_url'] ); ?>" class="btn btn-primary btn-large"><?php echo esc_html( $atts['button_text'] ); ?></a>
<?php endif; ?>
</div>
</section>
<?php
return ob_get_clean();
}
add_shortcode( 'cta', 'hogelandlinux_shortcode_cta' );
/**
* Shortcode: a stat tile (used in the Windows EOL stats).
* [stat icon="💻" number="1+ miljard" label="Windows 10 computers wereldwijd"]
*/
function hogelandlinux_shortcode_stat( $atts ) {
$atts = shortcode_atts(
array(
'icon' => '',
'number' => '',
'label' => '',
),
$atts,
'stat'
);
return '<div class="stat"><div class="stat-icon">' . $atts['icon'] . '</div><h3>' . esc_html( $atts['number'] ) . '</h3><p>' . esc_html( $atts['label'] ) . '</p></div>';
}
add_shortcode( 'stat', 'hogelandlinux_shortcode_stat' );
/**
* Shortcode: a collapsible disclaimer.
* [disclaimer summary="Lees de back-updisclaimer"]Body[/disclaimer]
*/
function hogelandlinux_shortcode_disclaimer( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'summary' => '',
),
$atts,
'disclaimer'
);
return '<details class="disclaimer"><summary>' . esc_html( $atts['summary'] ) . '</summary><div class="disclaimer-body">' . do_shortcode( $content ) . '</div></details>';
}
add_shortcode( 'disclaimer', 'hogelandlinux_shortcode_disclaimer' );