templates-functions.php (16028B)
1 <?php 2 3 function materialis_get_current_template() 4 { 5 global $template; 6 7 $current_template = str_replace("\\", "/", $template); 8 $pathParts = explode("/", $current_template); 9 $current_template = array_pop($pathParts); 10 11 return $current_template; 12 } 13 14 function materialis_is_page_template() 15 { 16 17 $templates = wp_get_theme()->get_page_templates(); 18 $templates = array_keys($templates); 19 $templates[] = "woocommerce.php"; 20 21 $current_template = materialis_get_current_template(); 22 23 foreach ($templates as $_template) { 24 if ($_template === $current_template) { 25 return true; 26 } 27 28 } 29 30 return false; 31 32 } 33 34 /** 35 * @param bool $is_homepage_template 36 * 37 * @return bool 38 */ 39 40 function materialis_is_front_page($is_homepage_template = false) 41 { 42 $is_front_page = (is_front_page() && !is_home() && !is_archive()); 43 $template = materialis_get_current_template(); 44 45 if ($is_front_page && $template !== "homepage.php") { 46 $is_front_page = false; 47 } else { 48 if ($is_homepage_template && !$is_front_page && $template === "homepage.php") { 49 $is_front_page = true; 50 } 51 } 52 53 $is_front_page = apply_filters('materialis_is_front_page', $is_front_page, $is_homepage_template, $template); 54 55 return $is_front_page; 56 } 57 58 function materialis_is_inner_page($include_fp_template = false) 59 { 60 global $post; 61 62 return ($post && $post->post_type === "page" && !materialis_is_front_page($include_fp_template)); 63 } 64 65 function materialis_is_inner($include_fp_template = false) 66 { 67 68 return !materialis_is_front_page($include_fp_template); 69 } 70 71 function materialis_is_blog() 72 { 73 return (is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag()) && 'post' == get_post_type(); 74 } 75 76 function materialis_page_content_wrapper_class($default = array()) 77 { 78 79 $class = array('gridContainer', 'content'); 80 $class = apply_filters('materialis_page_content_wrapper_class', $class); 81 $class = $class + $default; 82 $class = array_unique($class); 83 84 echo esc_attr(implode(' ', $class)); 85 } 86 87 function materialis_page_content_class() 88 { 89 $class = apply_filters('materialis_page_content_class', array()); 90 91 echo esc_attr(implode(' ', $class)); 92 } 93 94 function materialis_posts_wrapper_class() 95 { 96 $class = is_active_sidebar('sidebar-1') ? 'col-sm-8 col-md-9' : 'col-sm-12'; 97 98 if (!apply_filters('materialis_blog_sidebar_enabled', true)) { 99 $class = 'col-sm-12'; 100 } 101 102 echo esc_attr($class); 103 } 104 105 function materialis_get_header($header = null) 106 { 107 $name = apply_filters('materialis_header', $header); 108 109 if ( ! $name) { 110 $name = $header; 111 } 112 113 114 do_action("materialis_before_header", $name); 115 116 $fileName = $name ? "header-{$name}" : "header"; 117 118 $isInPro = locate_template("pro/{$fileName}.php"); 119 120 if ($isInPro) { 121 do_action('get_header', $name); 122 locate_template("/pro/{$fileName}.php", true); 123 } 124 125 if ( ! $isInPro) { 126 get_header($name); 127 } 128 129 } 130 131 function materialis_get_sidebar($name = null) 132 { 133 $isInPRO = locate_template("pro/sidebar-{$name}.php", false); 134 135 if ($isInPRO) { 136 do_action('get_sidebar', $name); 137 locate_template("pro/sidebar-{$name}.php", true); 138 } 139 140 if ( ! $isInPRO) { 141 get_sidebar($name); 142 } 143 } 144 145 function materialis_get_navigation($navigation = null) 146 { 147 $template = apply_filters('materialis_navigation', null); 148 149 if ( ! $template || $template === "default") { 150 $template = $navigation; 151 } 152 153 get_template_part('template-parts/navigation/navigation', $template); 154 } 155 156 function materialis_header_main_class() 157 { 158 $inner = materialis_is_inner(true); 159 $classes = array(); 160 161 $prefix = $inner ? "inner_header" : "header"; 162 163 if (materialis_get_theme_mod("{$prefix}_nav_boxed", false)) { 164 $classes[] = "boxed"; 165 } 166 167 $transparent_nav = materialis_get_theme_mod($prefix . '_nav_transparent', materialis_mod_default("{$prefix}_nav_transparent")); 168 169 if ( ! $transparent_nav) { 170 $classes[] = "coloured-nav"; 171 } 172 173 if (materialis_get_theme_mod("{$prefix}_nav_border", materialis_mod_default("{$prefix}_nav_border"))) { 174 $classes[] = "bordered"; 175 } 176 177 if (materialis_is_front_page(true)) { 178 $classes[] = "homepage"; 179 } 180 181 $classes = apply_filters("materialis_header_main_class", $classes, $prefix); 182 183 echo esc_attr(implode(" ", $classes)); 184 } 185 186 187 function materialis_print_logo($footer = false) 188 { 189 190 $preview_atts = ""; 191 if (materialis_is_customize_preview()) { 192 $preview_atts = "data-focus-control='blogname'"; 193 } 194 195 if ($footer) { 196 printf('<span data-type="group" ' . $preview_atts . ' data-dynamic-mod="true">%1$s</span>', esc_html(get_bloginfo('name'))); 197 198 return; 199 } 200 201 if (function_exists('has_custom_logo') && has_custom_logo()) { 202 $dark_logo_image = materialis_get_theme_mod('logo_dark', false); 203 if ($dark_logo_image) { 204 $dark_logo_html = sprintf('<a href="%1$s" class="logo-link dark" rel="home" itemprop="url">%2$s</a>', 205 esc_url(home_url('/')), 206 wp_get_attachment_image(absint($dark_logo_image), 'full', false, array( 207 'class' => 'logo dark', 208 'itemprop' => 'logo', 209 )) 210 ); 211 212 echo $dark_logo_html; 213 } 214 215 the_custom_logo(); 216 } else { 217 printf('<a class="text-logo" data-type="group" ' . $preview_atts . ' data-dynamic-mod="true" href="%1$s">%2$s</a>', esc_url(home_url('/')), materialis_bold_text(get_bloginfo('name'))); 218 } 219 } 220 221 function materialis_single_item_title($before = "", $after = "") 222 { 223 if (materialis_get_theme_mod('show_single_item_title', true)) { 224 the_title($before, $after); 225 } 226 } 227 228 229 if ( ! function_exists('materialis_print_header_content_holder_class')) { 230 function materialis_print_header_content_holder_class() 231 { 232 $align = materialis_get_theme_mod('header_text_box_text_align', materialis_mod_default('header_text_box_text_align')); 233 234 $shadow_class = ''; 235 $background_enabled = materialis_get_theme_mod('header_text_box_background_enabled', false); 236 $shadow_value = materialis_get_theme_mod('header_text_box_background_shadow', 0); 237 238 if ($background_enabled && $shadow_value) { 239 $shadow_class = 'mdc-elevation--z' . $shadow_value . " "; 240 } 241 242 echo "align-holder " . esc_attr($shadow_class . $align); 243 } 244 } 245 246 247 //FOOTER FUNCTIONS 248 249 function materialis_get_footer_content($footer = null) 250 { 251 $template = apply_filters('materialis_footer', null); 252 253 if ( ! $template) { 254 $template = $footer; 255 } 256 257 $slug = 'template-parts/footer/footer'; 258 259 if (locate_template("pro/{$slug}-{$template}.php")) { 260 $slug = "pro/{$slug}"; 261 } 262 263 get_template_part($slug, $template); 264 } 265 266 function materialis_get_footer_copyright() 267 { 268 $copyrightText = sprintf( 269 // Translators: %s is the link to the theme. 270 esc_html__('Built using WordPress and the %s', 'materialis'), 271 '<a rel="nofollow" target="_blank" href="https://extendthemes.com/go/built-with-materialis/">' . __('Materialis Theme', 'materialis') . '</a>' 272 ); 273 274 $previewAtts = ""; 275 276 if (materialis_is_customize_preview()) { 277 $previewAtts = 'data-footer-copyright="true"'; 278 } 279 280 $copyright = '<p ' . $previewAtts . ' class="copyright">© ' . " " . date_i18n(__('Y', 'materialis')) . ' ' . esc_html(get_bloginfo('name')) . '. ' . wp_kses_post($copyrightText) . '</p>'; 281 282 return apply_filters('materialis_get_footer_copyright', $copyright, $previewAtts); 283 } 284 285 function materialis_get_footer_copyright_small() 286 { 287 $previewAtts = ""; 288 if (materialis_is_customize_preview()) { 289 $previewAtts = 'data-footer-copyright="true"'; 290 } 291 $copyright = '<p ' . $previewAtts . ' class="copyright">© ' . " " . date_i18n(__('Y', 'materialis')) . ' ' . esc_html(get_bloginfo('name')) . '</p>'; 292 293 return apply_filters('materialis_get_footer_copyright', $copyright, $previewAtts); 294 } 295 296 // PAGE FUNCTIONS 297 298 function materialis_print_pagination($args = array(), $class = 'pagination') 299 { 300 if ($GLOBALS['wp_query']->max_num_pages <= 1) { 301 return; 302 } 303 304 $args = wp_parse_args($args, array( 305 'mid_size' => 2, 306 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __('Page', 'materialis') . ' </span>', 307 'prev_text' => __('<i class="mdi mdi-arrow-left"></i>', 'materialis'), 308 'next_text' => __('<i class="mdi mdi-arrow-right"></i>', 'materialis'), 309 'screen_reader_text' => __('Posts navigation', 'materialis'), 310 )); 311 312 $links = paginate_links($args); 313 314 $next_link = get_previous_posts_link('<i class="mdi mdi-arrow-left"></i>'); 315 $prev_link = get_next_posts_link('<i class="mdi mdi-arrow-right"></i>'); 316 317 $template = apply_filters('materialis_pagination_navigation_markup_template', ' 318 <div class="navigation %1$s" role="navigation"> 319 <h2 class="screen-reader-text">%2$s</h2> 320 <div class="nav-links mdc-elevation--z1"><div class="prev-navigation">%3$s</div><div class="numbers-navigation">%4$s</div><div class="next-navigation">%5$s</div></div> 321 </div>', $args, $class); 322 323 echo sprintf($template, esc_attr($class), $args['screen_reader_text'], $next_link, $links, $prev_link); 324 } 325 326 // POSTS, LIST functions 327 328 function materialis_print_archive_entry_class() 329 { 330 global $wp_query; 331 $classes = array("post-list-item", "col-xs-12", "space-bottom"); 332 $index = $wp_query->current_post; 333 334 $hasBigClass = ($index === 0 && apply_filters('materialis_archive_post_highlight', true)); 335 $showBigEntry = (is_archive() || is_home()); 336 337 if ($showBigEntry && $hasBigClass) { 338 $classes[] = "col-sm-12 col-md-12 highlighted-post"; 339 } else { 340 $postsPerRow = apply_filters('materialis_posts_per_row', 2); 341 $postsPerRow = $postsPerRow === 0 ? 1 : $postsPerRow; 342 $colSize = 12 / intval($postsPerRow); 343 $classes[] = "col-sm-12 col-md-{$colSize}"; 344 if ($colSize !== 12) { 345 $classes[] = "multiple-per-row"; 346 } 347 } 348 349 $classes = apply_filters('materialis_archive_entry_class', $classes); 350 351 $classesText = implode(" ", $classes); 352 353 echo esc_attr($classesText); 354 } 355 356 function materialis_print_masonry_col_class($echo = false) 357 { 358 359 global $wp_query; 360 $index = $wp_query->current_post; 361 $hasBigClass = ($index === 0 && apply_filters('materialis_archive_post_highlight', true)); 362 $showBigEntry = (is_archive() || is_home()); 363 364 $class = ""; 365 if ($showBigEntry && $hasBigClass) { 366 $class = "col-md-12"; 367 } else { 368 $postsPerRow = apply_filters('materialis_posts_per_row', 2); 369 $class = ".col-sm-12.col-md-" . (12 / intval($postsPerRow)); 370 } 371 372 if ($echo) { 373 echo esc_attr($class); 374 375 return; 376 } 377 378 return esc_attr($class); 379 } 380 381 function materialis_print_post_thumb_image() 382 { 383 if (has_post_thumbnail()) { 384 the_post_thumbnail(); 385 } else { 386 $placeholder_color = materialis_get_theme_mod('blog_post_thumb_placeholder_color', materialis_get_theme_colors('color1')); 387 $placeholder_color = maybe_hash_hex_color($placeholder_color); 388 ?> 389 <svg class="materialis-post-list-item-thumb-placeholder" width="890" height="580" viewBox="0 0 890 580" preserveAspectRatio="none"> 390 <rect width="890" height="580" style="fill:<?php echo esc_attr($placeholder_color); ?>;"></rect> 391 </svg> 392 <?php 393 } 394 } 395 396 function materialis_print_post_thumb($classes = "") 397 { 398 399 $show_placeholder = materialis_get_theme_mod('blog_show_post_thumb_placeholder', true); 400 if ( ! has_post_thumbnail() && ! $show_placeholder) { 401 return; 402 } 403 ?> 404 <div class="post-thumbnail"> 405 <a href="<?php the_permalink(); ?>" class="post-list-item-thumb <?php echo esc_attr($classes); ?>"> 406 <?php materialis_print_post_thumb_image(); ?> 407 </a> 408 </div> 409 <?php 410 } 411 412 function materialis_is_customize_preview() 413 { 414 $is_preview = (function_exists('is_customize_preview') && is_customize_preview()); 415 416 if ( ! $is_preview) { 417 $is_preview = apply_filters('materialis_is_shortcode_refresh', $is_preview); 418 } 419 420 return $is_preview; 421 422 } 423 424 function materialis_print_about_widget() 425 { 426 427 if (is_single() || is_author()) { 428 $author_data = get_user_by('ID', get_the_author_meta('ID')); 429 } else { 430 $author_data = get_user_by('email', get_option('admin_email')); 431 } 432 433 $author_description = get_the_author_meta('description', $author_data->ID); 434 $author_avatar = get_avatar_url($author_data->ID, array( 435 'size' => 160, 436 'default' => 'mystery', 437 'force_default' => false, 438 )); 439 440 if (materialis_get_theme_mod("show_author_about_box", false)): 441 ?> 442 <div id="about-box" class="widget_about mdc-elevation--z5"> 443 <div class="about-box-image mdc-elevation--z7" style="background-image: url(<?php echo esc_attr($author_avatar); ?>);"></div> 444 <h4><?php echo esc_html($author_data->display_name); ?></h4> 445 <p class="about-box-subheading"><?php echo(get_option('blogdescription')); ?></p> 446 <p class="about-box-description"><?php echo esc_html($author_description); ?></p> 447 <a href="<?php echo esc_url(get_author_posts_url($author_data->ID)) ?>" class="button white outline"><?php esc_html_e('About Me', 'materialis') ?></a> 448 </div> 449 <?php 450 endif; 451 } 452 453 function materialis_has_category() 454 { 455 $categories = get_the_category(); 456 457 return (count($categories) > 0); 458 } 459 460 function materialis_the_category($small_buttons = false) 461 { 462 $categories = get_the_category(); 463 $linkTemplate = '<a href="%1$s" class="button color5 link %3$s">%2$s</a>'; 464 $classes = $small_buttons ? "small" : ""; 465 466 467 if ( ! count($categories)) { 468 return; 469 } 470 471 if (is_archive() || ! is_single()) { 472 $after = (count($categories) > 1) ? "<span class='has-more-categories'>[…]</span>" : ""; 473 474 printf($linkTemplate . $after, 475 esc_url(get_category_link($categories[0]->term_id)), 476 esc_html($categories[0]->name), 477 esc_attr($classes) 478 ); 479 } else { 480 foreach ($categories as $category) { 481 printf($linkTemplate, 482 esc_url(get_category_link($category->term_id)), 483 esc_html($category->name), 484 esc_attr($classes) 485 ); 486 } 487 } 488 } 489 490 function materialis_footer_background($footer_class) 491 { 492 $attrs = array( 493 'class' => $footer_class . " ", 494 ); 495 496 $result = ""; 497 498 $attrs = apply_filters('materialis_footer_background_atts', $attrs); 499 500 foreach ($attrs as $key => $value) { 501 $value = esc_attr(trim($value)); 502 $key = esc_attr($key); 503 $result .= " {$key}='{$value}'"; 504 } 505 506 return $result; 507 } 508 509 function materialis_set_front_page_header_for_blog_as_home($header) 510 { 511 if (is_front_page()) { 512 $header = 'homepage'; 513 } 514 515 return $header; 516 } 517 518 add_filter('materialis_header', 'materialis_set_front_page_header_for_blog_as_home'); 519 520 function materialis_is_font_page_with_posts_only($value) 521 { 522 523 if (is_front_page() ) { 524 $value = true; 525 } 526 527 return $value; 528 } 529 530 add_filter('materialis_is_front_page', 'materialis_is_font_page_with_posts_only'); 531 532 533 function materialis_print_skip_link(){ 534 ?> 535 <style> 536 .screen-reader-text[href="#page-content"]:focus { 537 background-color: #f1f1f1; 538 border-radius: 3px; 539 box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6); 540 clip: auto !important; 541 clip-path: none; 542 color: #21759b; 543 544 } 545 </style> 546 <a class="skip-link screen-reader-text" href="#page-content"><?php _e('Skip to content', 'materialis'); ?></a> 547 <?php 548 }