twentyseventeen.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Infinite Scroll Theme Assets
  4. *
  5. * Register support for Twenty Seventeen.
  6. */
  7. /**
  8. * Add theme support for infinite scroll
  9. */
  10. function jetpack_twentyseventeen_infinite_scroll_init() {
  11. add_theme_support( 'infinite-scroll', array(
  12. 'container' => 'main',
  13. 'render' => 'jetpack_twentyseventeen_infinite_scroll_render',
  14. 'footer' => 'content',
  15. 'footer_widgets' => jetpack_twentyseventeen_has_footer_widgets(),
  16. ) );
  17. }
  18. add_action( 'init', 'jetpack_twentyseventeen_infinite_scroll_init' );
  19. /**
  20. * Custom render function for Infinite Scroll.
  21. */
  22. function jetpack_twentyseventeen_infinite_scroll_render() {
  23. while ( have_posts() ) {
  24. the_post();
  25. if ( is_search() ) {
  26. get_template_part( 'template-parts/post/content', 'search' );
  27. } else {
  28. get_template_part( 'template-parts/post/content', get_post_format() );
  29. }
  30. }
  31. }
  32. /**
  33. * Custom function to check for the presence of footer widgets or the social links menu
  34. */
  35. function jetpack_twentyseventeen_has_footer_widgets() {
  36. if ( is_active_sidebar( 'sidebar-2' ) ||
  37. is_active_sidebar( 'sidebar-3' ) ||
  38. has_nav_menu( 'social' ) ) {
  39. return true;
  40. }
  41. return false;
  42. }
  43. /**
  44. * Enqueue CSS stylesheet with theme styles for Infinite Scroll.
  45. */
  46. function jetpack_twentyseventeen_infinite_scroll_enqueue_styles() {
  47. if ( wp_script_is( 'the-neverending-homepage' ) ) {
  48. wp_enqueue_style( 'infinity-twentyseventeen', plugins_url( 'twentyseventeen.css', __FILE__ ), array( 'the-neverending-homepage' ), '20161219' );
  49. wp_style_add_data( 'infinity-twentyseventeen', 'rtl', 'replace' );
  50. }
  51. }
  52. add_action( 'wp_enqueue_scripts', 'jetpack_twentyseventeen_infinite_scroll_enqueue_styles', 25 );