Making WordPress.org

Ticket #3035: 3035.3.diff

File 3035.3.diff, 3.1 KB (added by Kau-Boy, 7 years ago)

Added body classes and categories to the single view content

  • wordcamp.org/public_html/wp-content/mu-plugins/wcorg-misc.php

    diff --git wordcamp.org/public_html/wp-content/mu-plugins/wcorg-misc.php wordcamp.org/public_html/wp-content/mu-plugins/wcorg-misc.php
    index a2f8038..1798952 100644
    function wcorg_content_slugs_to_body_tag( $body_classes ) { 
    202202}
    203203add_filter( 'body_class', 'wcorg_content_slugs_to_body_tag' );
    204204
     205
     206/**
     207 * Add the sessions's category slugs to the body tag
     208 *
     209 * @param array $body_classes
     210 *
     211 * @return array
     212 */
     213function wcorg_session_category_slugs_to_body_tag( $body_classes ) {
     214        global $wp_query;
     215        $post = $wp_query->get_queried_object();
     216
     217        if ( is_a( $post, 'WP_Post' ) && 'wcb_session' === $post->post_type ) {
     218                $session_categories   = get_the_terms( $post->ID, 'wcb_session_category' );
     219
     220                if ( is_array( $session_categories ) ) {
     221                        foreach ( $session_categories as $session_category ) {
     222                                $body_classes[] = 'wcb-session-category-' . $session_category->slug;
     223                        }
     224                }
     225        }
     226
     227        return $body_classes;
     228}
     229add_filter( 'body_class', 'wcorg_session_category_slugs_to_body_tag' );
     230
    205231/*
    206232 * Flush the rewrite rules on the current site.
    207233 *
  • wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php

    diff --git wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php wordcamp.org/public_html/wp-content/plugins/wc-post-types/wc-post-types.php
    index bbdca08..fd245dc 100644
    class WordCamp_Post_Types_Plugin { 
    5454                add_filter( 'the_content', array( $this, 'add_speaker_info_to_session_posts' ) );
    5555                add_filter( 'the_content', array( $this, 'add_slides_info_to_session_posts' ) );
    5656                add_filter( 'the_content', array( $this, 'add_video_info_to_session_posts' ) );
     57                add_filter( 'the_content', array( $this, 'add_session_categories_to_session_posts' ) );
    5758                add_filter( 'the_content', array( $this, 'add_session_info_to_speaker_posts' ) );
    5859
    5960                add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ) );
    class WordCamp_Post_Types_Plugin { 
    13531354        }
    13541355
    13551356        /**
     1357         * Add session's categories to Session posts
     1358         *
     1359         * @param string $content
     1360         *
     1361         * @return string
     1362         */
     1363        function add_session_categories_to_session_posts( $content ) {
     1364                global $post;
     1365
     1366                if ( ! $this->is_single_cpt_post( 'wcb_session' ) ) {
     1367                        return $content;
     1368                }
     1369
     1370                $session_categories_html = '';
     1371
     1372                $session_categories_list = get_the_term_list( $post->ID, 'wcb_session_category', '', _x( ', ', 'Used between list items, there is a space after the comma.', 'wordcamporg' ) );
     1373                if ( $session_categories_list ) {
     1374                        $session_categories_html = sprintf( '<span class="session-categories-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
     1375                                _x( 'Categories', 'Used before session category names.', 'wordcamporg' ),
     1376                                $session_categories_list
     1377                        );
     1378                }
     1379
     1380                return $content . $session_categories_html;
     1381        }
     1382
     1383        /**
    13561384         * Add session information to Speaker posts
    13571385         *
    13581386         * We don't enable it for sites that were created before it was committed, because some will have already