• in the post meta, by default the theme seems to only display the categories used if there are 2 or more.

    This is from the template-tags file (twentyseventeen_entry_footersection) in 2017

    	// Make sure there's more than one category before displaying.
    					if ( $categories_list && twentyseventeen_categorized_blog() ) {
    						echo '<span class="cat-links">' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>';
    					}

    and twentyseventeen_categorized_blog() is defined further down in template-tags as

    /**
     * Returns true if a blog has more than 1 category.
     *
     * @return bool
     */
    function twentyseventeen_categorized_blog() {
    	$category_count = get_transient( 'twentyseventeen_categories' );
    
    	if ( false === $category_count ) {
    		// Create an array of all the categories that are attached to posts.
    		$categories = get_categories(
    			array(
    				'fields'     => 'ids',
    				'hide_empty' => 1,
    				// We only need to know if there is more than one category.
    				'number'     => 2,
    			)
    		);
    
    		// Count the number of categories that are attached to the posts.
    		$category_count = count( $categories );
    
    		set_transient( 'twentyseventeen_categories', $category_count );
    	}
    
    	// Allow viewing case of 0 or 1 categories in post preview.
    	if ( is_preview() ) {
    		return true;
    	}
    
    	return $category_count > 1;
    }

    I have changed this in the child theme in use by removing references to twentyseventeen_categorized_blog(). in twentyseventeen_entry_footer

    if ( ! function_exists( 'twentyseventeen_entry_footer' ) ) :
        /**
         * Prints HTML with meta information for the categories, tags and comments.
         */
        function twentyseventeen_entry_footer() {
    
            /* translators: used between list items, there is a space after the comma */
            $separate_meta = __( ', ', 'twentyseventeen' );
    
            // Get Categories for posts.
            $categories_list = get_the_category_list( $separate_meta );
    
            // Get Tags for posts.
            $tags_list = get_the_tag_list( '', $separate_meta );
    
            // We don't want to output .entry-footer if it will be empty, so make sure its not.
            if ((( $categories_list)  || ($tags_list )) || get_edit_post_link() ) {
    
                echo '<footer class="entry-footer">';
    
                if ( 'post' === get_post_type() ) {
                    if ( $categories_list || $tags_list ) {
                        echo '<span class="cat-tags-links">';
    
                            // Make sure there's more than one category before displaying.
                        if  ($categories_list)  {
                            echo '<span class="cat-links">' . twentyseventeen_get_svg( array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>';
                        }
    
                        if ( $tags_list && ! is_wp_error( $tags_list ) ) {
                            echo '<span class="tags-links">' . twentyseventeen_get_svg( array( 'icon' => 'hashtag' ) ) . '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>';
                        }
    
                        echo '</span>';
                    }
                }
    
                twentyseventeen_edit_link();
    
                echo '</footer> <!-- .entry-footer -->';
            }
        }
    endif;

    and all works well. The post meta displays the category if there is only one category.

    My concern is that this would appear to be a deliberate choice by the theme author.
    Can doing what I have done have any negative effects.
    I ask because the following function defined in template-tags file

    /**
     * Flush out the transients used in twentyseventeen_categorized_blog.
     */
    function twentyseventeen_category_transient_flusher() {
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    		return;
    	}
    	// Like, beat it. Dig?
    	delete_transient( 'twentyseventeen_categories' );
    }
    add_action( 'edit_category', 'twentyseventeen_category_transient_flusher' );
    add_action( 'save_post', 'twentyseventeen_category_transient_flusher' );

    appears to be linked / used / associated with/in the first 2 parts of the template-tags from above.

    The page I need help with: [log in to see the link]

  • The topic ‘post meta number of categories set to minimum of 2?’ is closed to new replies.