extras.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Ixion
  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 ixion_body_classes( $classes ) {
  16. // Adds a class of group-blog to blogs with more than 1 published author.
  17. if ( is_multi_author() ) {
  18. $classes[] = 'group-blog';
  19. }
  20. // Adds a class of hfeed to non-singular pages.
  21. if ( ! is_singular() ) {
  22. $classes[] = 'hfeed';
  23. }
  24. // Add a class of no-sidebar when there is no sidebar present
  25. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  26. $classes[] = 'no-sidebar';
  27. }
  28. // Add a class of no-sidebar to the full-width page template
  29. if ( ( is_page_template( 'templates/full-width-page.php' ) || is_post_type_archive( 'jetpack-testimonial' ) ) && ! ( is_front_page() && is_page() ) ) {
  30. $classes[] = 'no-sidebar';
  31. }
  32. if ( is_front_page() && is_page() ) {
  33. $classes[] = 'page-template-front-page';
  34. }
  35. if ( ! is_front_page() && is_page() || is_single() ) {
  36. $classes[] = 'singular';
  37. }
  38. $button_text = get_theme_mod( 'ixion_button_text', '' );
  39. if ( '' !== $button_text ) {
  40. $classes[] = 'has-cta-button';
  41. }
  42. $blogdescription = get_bloginfo( 'description' );
  43. if ( ! empty( $blogdescription ) ) {
  44. $classes[] = 'has-description';
  45. }
  46. if ( 'blank' === get_theme_mod( 'header_textcolor' ) ) {
  47. $classes[] = 'header-text-hidden';
  48. }
  49. $featured_posts = ixion_get_featured_posts();
  50. if ( empty( $featured_posts ) ) {
  51. $classes[] = 'no-featured-posts';
  52. }
  53. if ( 'none' === get_theme_mod( 'ixion_header_overlay_opacity' ) ) {
  54. $classes[] = 'header-overlay-none';
  55. } else if ( 'light' === get_theme_mod( 'ixion_header_overlay_opacity' ) ) {
  56. $classes[] = 'header-overlay-light';
  57. } else if ( 'medium' === get_theme_mod( 'ixion_header_overlay_opacity' ) ) {
  58. $classes[] = 'header-overlay-medium';
  59. }
  60. if ( 'none' === get_theme_mod( 'ixion_featured_overlay_opacity' ) ) {
  61. $classes[] = 'featured-content-overlay-none';
  62. } else if ( 'light' === get_theme_mod( 'ixion_featured_overlay_opacity' ) ) {
  63. $classes[] = 'featured-content-overlay-light';
  64. } else if ( 'dark' === get_theme_mod( 'ixion_featured_overlay_opacity' ) ) {
  65. $classes[] = 'featured-content-overlay-dark';
  66. }
  67. return $classes;
  68. }
  69. add_filter( 'body_class', 'ixion_body_classes' );
  70. /**
  71. * Adds custom classes to the array of post classes.
  72. *
  73. * @param array $classes Classes for posts.
  74. * @return array
  75. */
  76. function ixion_post_classes( $classes ) {
  77. if ( ! has_post_thumbnail() ) {
  78. $classes[] = "no-featured-image";
  79. }
  80. return $classes;
  81. }
  82. add_filter( 'post_class', 'ixion_post_classes' );
  83. /**
  84. * Sets the authordata global when viewing single posts.
  85. *
  86. * It removes the need to call the_post() and rewind_posts() on single posts
  87. * to print information about the author before the loop.
  88. *
  89. * @global WP_Query $wp_query WordPress Query object.
  90. * @return void
  91. */
  92. function ixion_setup_author() {
  93. global $wp_query;
  94. if ( $wp_query->is_single() && isset( $wp_query->post ) ) {
  95. $GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
  96. }
  97. }
  98. add_action( 'wp', 'ixion_setup_author' );