Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jetpack for Theme Developers (wcmtl)

Jetpack for Theme Developers (wcmtl)

Kelly Dwan

July 05, 2015
Tweet

More Decks by Kelly Dwan

Other Decks in Technology

Transcript

  1. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> add_theme_support( 'title-tag' ); $background = array( 'default-color' => '71af3a', ); add_theme_support( 'custom-background', $background ); add_theme_support
  2. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $args = array( 'function' => 'prefix_my_function', ); add_theme_support( 'custom-feature', $args ); function prefix_my_function( $maybe_args ) { // Do some code here. // echo or return as needed. } callbacks
  3. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'infinite-scroll', array( 'type' => 'click', 'container' => 'main', 'posts_per_page' => 12, 'footer' => 'page', 'render' => 'prefix_is_render', ) ); } function prefix_is_render() { // Only needed if your loop is different than while( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); endwhile; } jetpack.php
  4. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'infinite-scroll', array( 'type' => 'click', 'container' => 'main', 'posts_per_page' => 12, 'footer' => 'page', 'render' => 'prefix_is_render', ) ); } function prefix_is_render() { // Only needed if your loop is different than while( have_posts() ) : the_post(); get_template_part( 'content', get_post_format() ); endwhile; } jetpack.php
  5. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'featured-content', array( 'filter' => 'prefix_get_featured_content', 'max_posts' => 6, 'post_types' => array( 'post' ), ) ); } function prefix_get_featured_posts(){ return apply_filters( 'prefix_get_featured_content', array() ); } jetpack.php
  6. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'featured-content', array( 'filter' => 'prefix_get_featured_content', 'max_posts' => 6, 'post_types' => array( 'post' ), ) ); } function prefix_get_featured_posts(){ return apply_filters( 'prefix_get_featured_content', array() ); } jetpack.php
  7. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $featured_posts = prefix_get_featured_posts(); foreach ( $featured_posts as $post ): setup_postdata( $post ); // Include the featured content template. get_template_part( 'content', 'featured' ); endforeach; wp_reset_postdata(); featured-content.php
  8. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'jetpack-portfolio' ); } jetpack.php
  9. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> <?php /** * Template Name: Portfolio Page Template * * @package illustratr */ …template code… portfolio-page.php Illustratr
  10. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $posts_per_page = get_option( 'jetpack_portfolio_posts_per_page', '10' ); $args = array( 'post_type' => 'jetpack-portfolio', 'posts_per_page' => $posts_per_page, ); $project_query = new WP_Query( $args ); if ( post_type_exists( 'jetpack-portfolio' ) && $project_query->have_posts() ) : portfolio-page.php Illustratr
  11. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $posts_per_page = get_option( 'jetpack_portfolio_posts_per_page', '10' ); $args = array( 'post_type' => 'jetpack-portfolio', 'posts_per_page' => $posts_per_page, ); $project_query = new WP_Query( $args ); if ( post_type_exists( 'jetpack-portfolio' ) && $project_query->have_posts() ) : portfolio-page.php Illustratr
  12. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $posts_per_page = get_option( 'jetpack_portfolio_posts_per_page', '10' ); $args = array( 'post_type' => 'jetpack-portfolio', 'posts_per_page' => $posts_per_page, ); $project_query = new WP_Query( $args ); if ( post_type_exists( 'jetpack-portfolio' ) && $project_query->have_posts() ) : portfolio-page.php Illustratr
  13. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'nova_menu_item' ); } jetpack.php
  14. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $loop = new WP_Query( [ 'post_type' => 'nova_menu_item' ] ); while ( $loop->have_posts() ) : $loop->the_post(); get_template_part( 'content', 'menu' ); endwhile; // end of the Menu Item Loop wp_reset_postdata(); page-menu.php Confit
  15. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> Nova_Restaurant::init( array( 'menu_tag' => 'section', 'menu_class' => 'menu-items', 'menu_header_tag' => 'header', 'menu_header_class' => 'menu-group-header', 'menu_title_tag' => 'h1', 'menu_title_class' => 'menu-group-title', 'menu_description_tag' => 'div', 'menu_description_class' => 'menu-group-description', ) ); page-menu.php Confit
  16. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'site-logo', array( 'size' => 'full', )); } jetpack.php
  17. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> if ( function_exists('jetpack_the_site_logo') ) { jetpack_the_site_logo(); } header.php
  18. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_site_logo( $html, $logo, $size ) { // do something with $html return $html; } add_filter( 'jetpack_the_site_logo', 'prefix_site_logo', 10, 3 ); jetpack.php
  19. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> <?php if ( function_exists('jetpack_breadcrumbs') ) : ?> <div class="navigation"> <?php jetpack_breadcrumbs(); ?> </div><!-- .navigation --> <?php endif; ?> page.php
  20. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> if ( ! class_exists( 'Jetpack_Custom_CSS' ) ) { require Jetpack::get_module_path( 'custom-css' ); } $color = get_query_var( 'prefix_color' ); $valid_color = preg_match( '/^[0-9a-f]{6}$/i', $color ); if ( ! $valid_color ) { die(); } $base_sass = file_get_contents('colors.scss'); $sass = '$base-color: #' . $color . '; ' . $base_sass; $css = Jetpack_Custom_CSS::minify( $sass, 'sass' ); header( 'Content-type: text/css; charset: UTF-8' ); echo $css; die(); dynamic-colors.php Umbra
  21. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> if ( ! class_exists( 'Jetpack_Custom_CSS' ) ) { require Jetpack::get_module_path( 'custom-css' ); } $color = get_query_var( 'prefix_color' ); $valid_color = preg_match( '/^[0-9a-f]{6}$/i', $color ); if ( ! $valid_color ) { die(); } $base_sass = file_get_contents('colors.scss'); $sass = '$base-color: #' . $color . '; ' . $base_sass; $css = Jetpack_Custom_CSS::minify( $sass, 'sass' ); header( 'Content-type: text/css; charset: UTF-8' ); echo $css; die(); dynamic-colors.php Umbra
  22. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> if ( ! class_exists( 'Jetpack_Custom_CSS' ) ) { require Jetpack::get_module_path( 'custom-css' ); } $color = get_query_var( 'prefix_color' ); $valid_color = preg_match( '/^[0-9a-f]{6}$/i', $color ); if ( ! $valid_color ) { die(); } $base_sass = file_get_contents('colors.scss'); $sass = '$base-color: #' . $color . '; ' . $base_sass; $css = Jetpack_Custom_CSS::minify( $sass, 'sass' ); header( 'Content-type: text/css; charset: UTF-8' ); echo $css; die(); dynamic-colors.php Umbra
  23. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $base-hue: hue($base-color); $body-background: hsl( $base-hue, 0, 97% ); $text-color: hsl( $base-hue, 4%, 26% ); body { background: $body-background; } body, button, input, select, textarea { color: $text-color; } colors.scss Umbra
  24. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> if ( ! class_exists( 'Jetpack_Custom_CSS' ) ) { require Jetpack::get_module_path( 'custom-css' ); } $color = get_query_var( 'prefix_color' ); $valid_color = preg_match( '/^[0-9a-f]{6}$/i', $color ); if ( ! $valid_color ) { die(); } $base_sass = file_get_contents('colors.scss'); $sass = '$base-color: #' . $color . '; ' . $base_sass; $css = Jetpack_Custom_CSS::minify( $sass, 'sass' ); header( 'Content-type: text/css; charset: UTF-8' ); echo $css; die(); dynamic-colors.php Umbra
  25. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> if ( ! class_exists( 'Jetpack_Custom_CSS' ) ) { require Jetpack::get_module_path( 'custom-css' ); } $color = get_query_var( 'prefix_color' ); $valid_color = preg_match( '/^[0-9a-f]{6}$/i', $color ); if ( ! $valid_color ) { die(); } $base_sass = file_get_contents('colors.scss'); $sass = '$base-color: #' . $color . '; ' . $base_sass; $css = Jetpack_Custom_CSS::minify( $sass, 'sass' ); header( 'Content-type: text/css; charset: UTF-8' ); echo $css; die(); dynamic-colors.php Umbra
  26. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> function prefix_jetpack_setup(){ add_theme_support( 'tonesque' ); } functions.php
  27. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $image_src = prefix_get_post_image( $post_id ); if ( ! $image_src ) { return false; } $image = new Tonesque( $image_src ); $color = $image->color(); dynamic-colors.php
  28. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $image_src = prefix_get_post_image( $post_id ); if ( ! $image_src ) { return false; } $image = new Tonesque( $image_src ); $color = $image->color(); dynamic-colors.php
  29. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $image_src = prefix_get_post_image( $post_id ); if ( ! $image_src ) { return false; } $image = new Tonesque( $image_src ); $color = $image->color(); dynamic-colors.php
  30. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 18 19 20 </> $image = new Tonesque( $image_src ); $background_color = $image->color(); $contrast = $image->contrast(); dynamic-colors.php