extras.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Custom functions that act independently of the theme templates.
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features.
  6. *
  7. * @package Lodestar
  8. */
  9. /**
  10. * Adds custom classes to the array of body classes.
  11. *
  12. * @param array $classes Classes for the body element.
  13. * @return array
  14. */
  15. function lodestar_body_classes( $classes ) {
  16. // Add class of group-blog to blogs with more than 1 published author.
  17. if ( is_multi_author() ) {
  18. $classes[] = 'group-blog';
  19. }
  20. // Add class of hfeed to non-singular pages.
  21. if ( ! is_singular() ) {
  22. $classes[] = 'hfeed';
  23. }
  24. // Add class if we're viewing the Customizer for easier styling of theme options
  25. if ( is_customize_preview() ) {
  26. $classes[] = 'lodestar-customizer';
  27. }
  28. // Add class on front page
  29. if ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) {
  30. $classes[] = 'lodestar-front-page';
  31. }
  32. // Add class if site has a Custom Logo
  33. if ( has_custom_logo() ) {
  34. $classes[] = 'has-site-logo';
  35. }
  36. // Add class if no custom header or featured images
  37. $header_image = get_header_image();
  38. if ( ! has_header_image() && ( ! has_post_thumbnail() || is_home() ) ) {
  39. $classes[] = 'no-header-image';
  40. }
  41. // Add class if footer image has been added
  42. $footer_image = get_theme_mod( 'lodestar_footer_image' );
  43. if ( isset( $footer_image ) ) {
  44. $classes[] = 'lodestar-footer-image';
  45. }
  46. // Add class if sidebar is used
  47. if ( is_active_sidebar( 'sidebar-1' ) && ! lodestar_is_frontpage() ) {
  48. $classes[] = 'has-sidebar';
  49. }
  50. // Add class if top header content is added or WooCommerce is active
  51. $lodestar_header_top_text_1 = get_theme_mod( 'lodestar_header_top_text_1' );
  52. $lodestar_header_top_text_2 = get_theme_mod( 'lodestar_header_top_text_2' );
  53. if ( '' !== $lodestar_header_top_text_1 || '' !== $lodestar_header_top_text_2 || class_exists( 'WooCommerce' ) ) {
  54. $classes[] = 'has-top-content';
  55. }
  56. return $classes;
  57. }
  58. add_filter( 'body_class', 'lodestar_body_classes' );
  59. /*
  60. * Count our number of active panels
  61. * Primarily used to see if we have any panels active, duh.
  62. */
  63. function lodestar_panel_count() {
  64. $panels = array( '1', '2', '3', '4' );
  65. $panel_count = 0;
  66. foreach ( $panels as $panel ) :
  67. if ( get_theme_mod( 'lodestar_panel' . $panel ) ) :
  68. $panel_count++;
  69. endif;
  70. endforeach;
  71. return $panel_count;
  72. }
  73. /**
  74. * Checks to see if we're on the homepage or not.
  75. */
  76. function lodestar_is_frontpage() {
  77. if ( is_front_page() && ! is_home() ) :
  78. return true;
  79. else :
  80. return false;
  81. endif;
  82. }
  83. /**
  84. * Adjust content_width value for portfolio page template.
  85. */
  86. function lodestar_portfolio_content_width() {
  87. if ( is_page_template( 'templates/portfolio-page.php' ) ) {
  88. $GLOBALS['content_width'] = 1120;
  89. }
  90. }
  91. add_action( 'template_redirect', 'lodestar_portfolio_content_width' );