• Resolved bvankat

    (@bvankat)


    I created a custom taxonomy and would like the option to display it in the post-meta section of the single-post template.

    1) The Customizer allows users to select post meta options for two sections – “Top Post Meta” and “Bottom Post Meta.” Is it possible to add my custom taxonomy to these lists in the Customizer?

    2) In functions.php, there’s a comment that suggests you can show additional meta items (without using the Customizer) by hooking into ‘chaplin_start_of_post_meta_list’ and ‘chaplin_end_of_post_meta_list’.

    The following code works as expected in the ‘single-top’ meta location, but the ‘single-bottom’ location doesn’t display a result when using ‘chaplin_end_of_post_meta_list’:

    
    add_action('chaplin_end_of_post_meta_list', 'add_custom_taxonomy');
    function add_custom_taxonomy() { 
    	echo '<li>Custom taxonomy list: code goes here</li>';
    } 
    

    Note: That code works for ‘single-bottom’ location if you hook into ‘chaplin_start_of_post_meta_list’. Only the single-bottom and chaplin_end_of_post_meta_list combination seems broken.

    Question 1: Is this a bug? Or am I doing it wrong?
    Question 2: How would I print the list of custom taxonomies applied to the post using this hook?

    Thanks so much if you’re able to answer these questions. I’ve been so impressed with the Chaplin theme so far. It’s spectacular.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @bvankat,

    First of all, I’m happy to hear that someone makes use of the actions and filters in the theme ?? It’s always difficult to know beforehand whether they will end up being used or not.

    You can add additional options to the Customizer settings for post meta using the chaplin_post_meta_choices_in_the_customizer filter, like this:

    
    if ( ! function_exists( 'chaplin_child_add_post_meta_option' ) ) :
    	function chaplin_child_add_post_meta_option( $post_meta_choices ) {
    
    		$post_meta_choices['custom_taxonomy'] = __( 'Custom Taxonomy', 'chaplin-child' );
    		return $post_meta_choices;
    
    	}
    	add_filter( 'chaplin_post_meta_choices_in_the_customizer', 'chaplin_child_add_post_meta_option' );
    endif;
    

    The code above will add the “Custom Taxonomy” option to the post meta settings in the Customizer. If you check it in either location and save, you can hook into either the chaplin_start_of_post_meta_list or chaplin_end_of_post_meta_list to check if your custom taxonomy is selected and output it’s meta accordingly, like this:

    if ( ! function_exists( 'chaplin_child_post_meta_append' ) ) :
    	function chaplin_child_post_meta_append( $post_meta, $post_id ) {
    
    		// Change this to the name of your custom taxonomy
    		$taxonomy_name = 'custom_taxonomy';
    
    		if ( in_array( $taxonomy_name, $post_meta ) && has_term( '', $taxonomy_name, $post_id ) ) : ?>
    
    			<li class="custom-taxonomy meta-wrapper">
    				<span class="meta-icon">
    					<span class="screen-reader-text"><?php esc_html_e( 'Custom taxonomy', 'chaplin-child' ); ?></span>
    					<?php chaplin_the_theme_svg( 'folder' ); ?>
    				</span>
    				<span class="meta-text">
    					<?php esc_html_e( 'In', 'chaplin-child' ); ?> <?php the_terms( $post_id, $taxonomy_name, '', ', ' ); ?>
    				</span>
    			</li>
    
    			<?php
    		endif;
    
    	}
    	add_action( 'chaplin_start_of_post_meta_list', 'chaplin_child_post_meta_append', 10, 2 );
    endif;

    Well, you can really only hook into chaplin_start_of_post_meta_list right now – you’re correct that there’s a bug with chaplin_end_of_post_meta_list. Thedo_action()` call is wrapped with the conditional for outputting the edit post link, so the action only gets triggered when the edit post link is output. I’ll have a fix for that in the next version of Chaplin. Once it’s live, you should be able to output a list for your custom taxonomy using either action with the code above.

    Let me know how it goes! Really happy you like Chaplin.

    — Anders

    Thread Starter bvankat

    (@bvankat)

    I added your code and it’s working as expected. I’ll watch for the Chaplin update to fix the “chaplin_end_of_post_meta_list” bug.

    Thanks so much. Really appreciate your help on this.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Meta: Displaying custom taxonomy in single-post template’ is closed to new replies.