extras.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Affinity
  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 affinity_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 if a header image or featured header image is active
  21. if ( get_header_image() || ( affinity_has_post_thumbnail() && affinity_jetpack_featured_image_display() && 'post' === get_post_type() ) || ( has_post_thumbnail() && is_singular() && affinity_jetpack_featured_image_display() ) ) {
  22. $classes[] = 'custom-header-active';
  23. } else {
  24. $classes[] = 'no-custom-header';
  25. }
  26. //Adds a class if we're viewing the Customizer for easier styling of theme options
  27. if ( is_customize_preview() ) {
  28. $classes[] = 'affinity-customizer';
  29. }
  30. if ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) {
  31. $classes[] = 'affinity-front-page';
  32. }
  33. if ( ! is_active_sidebar( 'sidebar-1' ) ) {
  34. $classes[] = 'no-sidebar';
  35. }
  36. // Adds a class of hfeed to non-singular pages.
  37. if ( ! is_singular() ) {
  38. $classes[] = 'hfeed';
  39. }
  40. return $classes;
  41. }
  42. add_filter( 'body_class', 'affinity_body_classes' );
  43. /**
  44. * Adds custom classes to the array of post classes.
  45. *
  46. * @param array $classes Classes for the post element.
  47. * @return array
  48. */
  49. function affinity_post_classes( $classes ) {
  50. // Adds a class of affinity-panel to posts on the front page.
  51. if ( is_front_page() && 'page' == get_post_type() ) {
  52. $classes[] = 'affinity-panel';
  53. }
  54. if ( is_front_page() && 'page' == get_post_type() && ! has_post_thumbnail() ) {
  55. $classes[] = 'no-featured-image';
  56. }
  57. return $classes;
  58. }
  59. add_filter( 'post_class', 'affinity_post_classes' );
  60. /*
  61. * Count our number of active panels
  62. * Primarily used to see if we have any panels active, duh.
  63. */
  64. function affinity_panel_count() {
  65. $panels = array( '1', '2', '3', '4', '5' );
  66. $panel_count = 0;
  67. foreach ( $panels as $panel ) :
  68. if ( get_theme_mod( 'affinity_panel' . $panel ) ) :
  69. $panel_count++;
  70. endif;
  71. endforeach;
  72. return $panel_count;
  73. }