500 lines
14 KiB
PHP
500 lines
14 KiB
PHP
<?php
|
|
|
|
function kit_setup() {
|
|
|
|
load_theme_textdomain( 'kit', get_template_directory() . '/languages' );
|
|
|
|
add_theme_support( 'menus' );
|
|
add_theme_support( 'post-thumbnails' );
|
|
add_theme_support( 'custom-logo' );
|
|
|
|
};
|
|
|
|
add_action( 'after_setup_theme', 'kit_setup' );
|
|
|
|
# Registering menus
|
|
|
|
register_nav_menus( array(
|
|
'primary' => 'Main Menu',
|
|
'secondary' => 'Footer Menu',
|
|
'extra' => 'Extra Menu'
|
|
) );
|
|
|
|
function add_menu_link_class( $atts, $item, $args ) {
|
|
if (property_exists($args, 'link_class')) {
|
|
$atts['class'] = $args->link_class;
|
|
}
|
|
return $atts;
|
|
}
|
|
|
|
add_filter( 'nav_menu_link_attributes', 'add_menu_link_class', 1, 3 );
|
|
|
|
class kit_custom_main_menu extends Walker_Nav_Menu {
|
|
|
|
# Menu start, equivalent to <ul>
|
|
function start_lvl( &$output, $depth = 0, $args = array() ) {
|
|
|
|
// depth dependent classes
|
|
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
|
|
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
|
|
$classes = array(
|
|
'sub-menu',
|
|
'menu-depth-' . $display_depth
|
|
);
|
|
$class_names = implode( ' ', $classes );
|
|
|
|
// build html
|
|
if ($display_depth == 1) {
|
|
$output .= "\n" . $indent . '
|
|
<div class="nav-first-level-opener">
|
|
<span>Untermenu öffnen / schließen</span>
|
|
</div>
|
|
<section class="nav-second-level mega-flyout">
|
|
<div class="content-wrap">
|
|
<div class="container container-3-cols">
|
|
' . "\n";
|
|
} else {
|
|
$output .= "\n" . $indent . '<ul>' . "\n";
|
|
}
|
|
}
|
|
|
|
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
|
|
|
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
|
|
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
|
|
$classes = array(
|
|
'sub-menu',
|
|
'menu-depth-' . $display_depth
|
|
);
|
|
$class_names = implode( ' ', $classes );
|
|
|
|
// build html
|
|
if ($display_depth == 1) {
|
|
$output .= "\n" . $indent . '
|
|
</div>
|
|
</div>
|
|
</section>' . "\n";
|
|
} else {
|
|
$output .= "\n" . $indent . '</ul>' . "\n";
|
|
}
|
|
}
|
|
|
|
# Menu element, equivalent to <li>
|
|
function start_el(&$output, $item, $depth = 0, $args=array(), $id = 0) {
|
|
$object = $item->object;
|
|
$type = $item->type;
|
|
$title = $item->title;
|
|
$description = $item->description;
|
|
$permalink = $item->url;
|
|
|
|
$theme_template_path = get_template_directory_uri();
|
|
|
|
if ($depth == 1) {
|
|
$output .= '
|
|
<div class="column">
|
|
<div class="nav-second-level-group">
|
|
<a class="nav-second-level-group-headline" href="' . $permalink . '">
|
|
<div class="icon"></div>
|
|
<span>
|
|
';
|
|
$output .= $title;
|
|
$output .= '
|
|
</span>
|
|
</a>
|
|
<div class="nav-second-level-opener">
|
|
<span>Untermenu öffnen / schließen</span>
|
|
</div>';
|
|
} elseif ($depth == 2) {
|
|
$output .= "<li class='" . implode(" ", $item->classes) . "'>";
|
|
$output .= '
|
|
<a href="' . $permalink . '">';
|
|
$output .= $title;
|
|
$output .= ' </a>';
|
|
} else {
|
|
$output .= "<li class='" . implode(" ", $item->classes) . "'>";
|
|
$output .= '<a href="' . $permalink . '">';
|
|
$output .= $title;
|
|
$output .= '</a>';
|
|
}
|
|
}
|
|
|
|
function end_el(&$output, $item, $depth = 0, $args=array(), $id = 0) {
|
|
$object = $item->object;
|
|
$type = $item->type;
|
|
$title = $item->title;
|
|
$description = $item->description;
|
|
$permalink = $item->url;
|
|
|
|
if ($depth == 1) {
|
|
$output .= '
|
|
</div>
|
|
</div>';
|
|
} else {
|
|
$output .= '</li>';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
# Custom size settings for customizer
|
|
|
|
function theme_customize_register( $wp_customize ) {
|
|
|
|
$wp_customize->add_setting( 'theme_color', array(
|
|
'default' => '#009982',
|
|
'transport' => 'refresh',
|
|
) );
|
|
|
|
$wp_customize->add_control( new WP_Customize_Color_Control(
|
|
$wp_customize, 'theme_color', array(
|
|
'section' => 'colors',
|
|
'label' => esc_html__( 'Theme color', 'theme' ),
|
|
) ) );
|
|
|
|
$wp_customize->add_setting( 'kit_sidenav-mail', array(
|
|
'default' => '',
|
|
'type' => 'option',
|
|
'capability' => 'edit_theme_options'
|
|
),
|
|
);
|
|
|
|
$wp_customize->add_control( new WP_Customize_Control(
|
|
$wp_customize, 'sidenav_mail_control', array(
|
|
'label' => __( 'Contact mail', 'kit' ),
|
|
'description' => __( 'Mail address used in sidebar menu', 'kit' ),
|
|
'settings' => 'kit_sidenav-mail',
|
|
'priority' => 10,
|
|
'section' => 'title_tagline',
|
|
'type' => 'text',
|
|
)
|
|
) );
|
|
|
|
$wp_customize->add_setting( 'kit_sidenav-faqpage', array(
|
|
'sanitize_callback' => 'absint',
|
|
'default' => ''
|
|
),
|
|
);
|
|
|
|
$wp_customize->add_control( new WP_Customize_Control(
|
|
$wp_customize, 'kit_sidenav-faqpage', array(
|
|
'label' => __( 'FAQ page', 'kit' ),
|
|
'description' => __( 'FAQ page used in sidebar menu', 'kit' ),
|
|
'settings' => 'kit_sidenav-faqpage',
|
|
'section' => 'title_tagline',
|
|
'type' => 'dropdown-pages',
|
|
)
|
|
) );
|
|
|
|
$wp_customize->add_setting( 'kit_copyrighttext', array(
|
|
'default' => '',
|
|
'type' => 'option',
|
|
'capability' => 'edit_theme_options'
|
|
),
|
|
);
|
|
|
|
$wp_customize->add_control( new WP_Customize_Control(
|
|
$wp_customize, 'sidenav_copyrighttext', array(
|
|
'label' => __( 'Copyright text', 'kit' ),
|
|
'description' => __( 'Displayed in the footer', 'kit' ),
|
|
'settings' => 'kit_copyrighttext',
|
|
'section' => 'title_tagline',
|
|
'type' => 'text',
|
|
)
|
|
) );
|
|
|
|
$wp_customize->add_setting( 'kit_defaultimage' );
|
|
$wp_customize->add_control( new WP_Customize_Media_Control(
|
|
$wp_customize, 'kit_defaultimage', array(
|
|
'label' => __( 'Default featured image', 'kit' ),
|
|
'settings' => 'kit_defaultimage',
|
|
'section' => 'title_tagline',
|
|
)
|
|
) );
|
|
|
|
}
|
|
|
|
add_action( 'customize_register', 'theme_customize_register' );
|
|
|
|
# Apply custom CSS settings
|
|
|
|
function hex2rgba($color, $opacity = false) {
|
|
|
|
$default = 'rgb(0,0,0)';
|
|
|
|
//Return default if no color provided
|
|
if(empty($color))
|
|
return $default;
|
|
|
|
//Sanitize $color if "#" is provided
|
|
if ($color[0] == '#' ) {
|
|
$color = substr( $color, 1 );
|
|
}
|
|
|
|
//Check if color has 6 or 3 characters and get values
|
|
if (strlen($color) == 6) {
|
|
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
|
|
} elseif ( strlen( $color ) == 3 ) {
|
|
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
|
|
} else {
|
|
return $default;
|
|
}
|
|
|
|
//Convert hexadec to rgb
|
|
$rgb = array_map('hexdec', $hex);
|
|
|
|
//Check if opacity is set(rgba or rgb)
|
|
if($opacity){
|
|
if(abs($opacity) > 1)
|
|
$opacity = 1.0;
|
|
$output = 'rgba('.implode(",",$rgb).','.$opacity.')';
|
|
} else {
|
|
$output = 'rgb('.implode(",",$rgb).')';
|
|
}
|
|
|
|
//Return rgb(a) color string
|
|
return $output;
|
|
}
|
|
|
|
function kit_customize_css()
|
|
{
|
|
$theme_color = get_theme_mod('theme_color', '#009982');
|
|
?>
|
|
<style type="text/css">
|
|
aside .aside-icon {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
nav > ul > li:hover > a,
|
|
nav > ul > li:active > a {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
/* change color on hover for language selector on mobile view */
|
|
.header-lang-small:hover li.active span {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.header-lang-small:hover .icon {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.dropdown-content li:hover span {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
nav > ul > li:hover > a::after,
|
|
nav > ul > li:active > a::after {
|
|
border-bottom: 4px solid <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.header-button {
|
|
/* background-image: linear-gradient(0deg, <?php echo $theme_color; ?>, rgb(0,0,0,0.2)); */
|
|
background-color: <?php echo $theme_color; ?>;
|
|
box-shadow: inset 0 14px 16px -16px white;
|
|
}
|
|
|
|
.nav-second-level-group-headline {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.opened > a {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
nav > ul > li .nav-first-level-opener::before, nav > ul > li .nav-first-level-opener::after {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.nav-second-level .nav-second-level-opener::before, .nav-second-level .nav-second-level-opener::after {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.headline-element h2::after {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
form input[type='submit'] {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-searchbox form fieldset .tx-indexedsearch-search-submit button {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-browsebox ul li.current a {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-browsebox ul li a:hover {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-res {
|
|
border-bottom: 1px solid <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-res .tx-indexedsearch-title a:hover {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-res .link-more span:hover {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch .tx-indexedsearch-browsebox ul li .current {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.nav-second-level-group-headline .icon {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.header-lang li a:hover {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.header-lang li.active span {
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
h2::after {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.page-category-marker {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.teaser-box-color-brand-secondary .teaser-box-category-marker {
|
|
border-bottom-color: <?php echo $theme_color; ?>;
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.teaser-box-color-brand-secondary .teaser-box-category-marker:hover {
|
|
filter: brightness(120%);
|
|
}
|
|
|
|
.teaser-box-category-marker .icon {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.teaser-box-category-marker:hover {
|
|
border-bottom-color: <?php echo $theme_color; ?>;
|
|
color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
ul.catFilter li.available:hover {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
ul.catFilter li.active {
|
|
background-color: <?php echo $theme_color; ?>;
|
|
}
|
|
|
|
.tx-indexedsearch-redMarkup {
|
|
font-weight: 400;
|
|
background-color: <?php echo hex2rgba($theme_color,0.1); ?>;
|
|
}
|
|
|
|
</style>
|
|
<?php
|
|
}
|
|
|
|
add_action( 'wp_head', 'kit_customize_css');
|
|
|
|
# Search customizations
|
|
|
|
function kit_modify_posts_per_page( $query ) {
|
|
if ( $query->is_search() ) {
|
|
$query->set( 'posts_per_page', '10' );
|
|
} else {
|
|
$query->set( 'posts_per_page', '9' );
|
|
}
|
|
}
|
|
add_action( 'pre_get_posts', 'kit_modify_posts_per_page' );
|
|
|
|
# Register widget area
|
|
|
|
function kit_widgets_init() {
|
|
|
|
register_sidebar( array(
|
|
'name' => 'Custom Footer Widget Area',
|
|
'id' => 'custom-footer-widget',
|
|
'before_widget' => '<div class="content-wrap">',
|
|
'after_widget' => '</div>',
|
|
'before_title' => '<h2 class="chw-title">',
|
|
'after_title' => '</h2>',
|
|
) );
|
|
|
|
}
|
|
add_action( 'widgets_init', 'kit_widgets_init' );
|
|
|
|
# Highlight query in search results
|
|
|
|
function generate_excerpt($text, $query, $length) {
|
|
|
|
$words = explode(' ', $text);
|
|
$total_words = count($words);
|
|
|
|
if ($total_words > $length) {
|
|
|
|
$queryLow = array_map('strtolower', $query);
|
|
$wordsLow = array_map('strtolower', $words);
|
|
|
|
for ($i=0; $i <= $total_words; $i++) {
|
|
|
|
foreach ($queryLow as $queryItem) {
|
|
|
|
if (preg_match("/\b$queryItem\b/", $wordsLow[$i])) {
|
|
$posFound = $i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($posFound) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($i > ($length+($length/2))) {
|
|
$i = $i - ($length/2);
|
|
} else {
|
|
$i = 0;
|
|
}
|
|
|
|
}
|
|
|
|
$cutword = array_splice($words,$i,$length);
|
|
$excerpt = implode(' ', $cutword);
|
|
|
|
$keys = implode('|', $query);
|
|
$excerpt = preg_replace('/(' . $keys .')/iu', '<strong class="tx-indexedsearch-redMarkup">\0</strong>', $excerpt);
|
|
$excerptRet = '<p>';
|
|
if ($i !== 0) {
|
|
$excerptRet .= '... ';
|
|
}
|
|
$excerptRet .= $excerpt . ' ...</p>';
|
|
|
|
return $excerptRet;
|
|
|
|
}
|
|
|
|
function search_excerpt_highlight() {
|
|
|
|
# Length in word count
|
|
$excerptLength = 32;
|
|
|
|
$text = wp_strip_all_tags( get_the_content() );
|
|
|
|
# Filter double quotes from query. They will
|
|
# work on the results side but won't help with
|
|
# text highlighting and displaying.
|
|
$query=get_search_query(false);
|
|
$query=str_replace('"','',$query);
|
|
$query=esc_html($query);
|
|
|
|
$query = explode(' ', $query);
|
|
|
|
echo generate_excerpt($text, $query, $excerptLength);
|
|
|
|
}
|