jetpack.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Jetpack Compatibility File
  4. * See: http://jetpack.me/
  5. *
  6. * @package Sketch
  7. */
  8. /**
  9. * Add theme support for Infinite Scroll.
  10. * See: http://jetpack.me/support/infinite-scroll/
  11. */
  12. function sketch_jetpack_setup() {
  13. add_theme_support( 'infinite-scroll', array(
  14. 'container' => 'main',
  15. 'posts_per_page' => 9,
  16. 'footer' => 'page',
  17. 'render' => 'sketch_infinite_scroll_render',
  18. 'wrapper' => false,
  19. ) );
  20. add_theme_support( 'featured-content', array(
  21. 'filter' => 'sketch_get_featured_posts',
  22. 'max_posts' => 10,
  23. 'post_types' => array( 'post', 'page', 'jetpack-portfolio' ),
  24. ) );
  25. /**
  26. * Add theme support for Responsive Videos.
  27. */
  28. add_theme_support( 'jetpack-responsive-videos' );
  29. /**
  30. * Add theme support for Jetpack portfolios
  31. */
  32. add_theme_support( 'jetpack-portfolio', array(
  33. 'title' => true,
  34. 'content' => true,
  35. 'featured-image' => true,
  36. ) );
  37. /**
  38. * Add theme support for site logos
  39. */
  40. add_theme_support( 'site-logo', array(
  41. 'size' => 'sketch-site-logo'
  42. ) );
  43. }
  44. add_action( 'after_setup_theme', 'sketch_jetpack_setup' );
  45. /**
  46. * Define the code that is used to render the posts added by Infinite Scroll.
  47. *
  48. * Includes the whole loop. Used to include the correct template part for the Portfolio CPT.
  49. */
  50. function sketch_infinite_scroll_render() {
  51. while ( have_posts() ) {
  52. the_post();
  53. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  54. get_template_part( 'content', 'portfolio' );
  55. } else {
  56. get_template_part( 'content', get_post_format() );
  57. }
  58. }
  59. }
  60. function sketch_get_featured_posts() {
  61. return apply_filters( 'sketch_get_featured_posts', array() );
  62. }
  63. function sketch_has_featured_posts( $minimum = 1 ) {
  64. if ( is_paged() )
  65. return false;
  66. $minimum = absint( $minimum );
  67. $featured_posts = apply_filters( 'sketch_get_featured_posts', array() );
  68. if ( ! is_array( $featured_posts ) )
  69. return false;
  70. if ( $minimum > count( $featured_posts ) )
  71. return false;
  72. return true;
  73. }
  74. /**
  75. * Portfolio Title.
  76. */
  77. function sketch_portfolio_title( $before = '', $after = '' ) {
  78. $jetpack_portfolio_title = get_option( 'jetpack_portfolio_title' );
  79. $title = '';
  80. if ( is_post_type_archive( 'jetpack-portfolio' ) ) {
  81. if ( isset( $jetpack_portfolio_title ) && '' != $jetpack_portfolio_title ) {
  82. $title = esc_html( $jetpack_portfolio_title );
  83. } else {
  84. $title = post_type_archive_title( '', false );
  85. }
  86. } elseif ( is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  87. $title = single_term_title( '', false );
  88. }
  89. echo $before . $title . $after;
  90. }
  91. /**
  92. * Portfolio Content.
  93. */
  94. function sketch_portfolio_content( $before = '', $after = '' ) {
  95. $jetpack_portfolio_content = get_option( 'jetpack_portfolio_content' );
  96. if ( is_tax() && get_the_archive_description() ) {
  97. echo $before . get_the_archive_description() . $after;
  98. } else if ( isset( $jetpack_portfolio_content ) && '' != $jetpack_portfolio_content ) {
  99. $content = convert_chars( convert_smilies( wptexturize( wp_kses_post( $jetpack_portfolio_content ) ) ) );
  100. echo $before . $content . $after;
  101. }
  102. }
  103. /**
  104. * Portfolio Featured Image.
  105. */
  106. function sketch_portfolio_featured_image( $before = '', $after = '' ) {
  107. $jetpack_portfolio_featured_image = get_option( 'jetpack_portfolio_featured_image' );
  108. if ( isset( $jetpack_portfolio_featured_image ) && '' != $jetpack_portfolio_featured_image ) {
  109. $featured_image = wp_get_attachment_image( (int) $jetpack_portfolio_featured_image, 'sketch-featured' );
  110. echo $before . $featured_image . $after;
  111. }
  112. }
  113. /**
  114. * Filter Infinite Scroll text handle.
  115. */
  116. function sketch_portfolio_infinite_scroll_navigation( $js_settings ) {
  117. if ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag' ) ) {
  118. $js_settings[ 'text' ] = esc_js( esc_html__( 'Older projects', 'sketch' ) );
  119. }
  120. return $js_settings;
  121. }
  122. add_filter( 'infinite_scroll_js_settings', 'sketch_portfolio_infinite_scroll_navigation' );