• Resolved griselidis

    (@webmaster9280)


    Hi Jeremy,

    I’d like to display your views counter in the metas of my posts with blocksy free or premium theme. When i add your php sequence in the child theme in function.php file, i obtain a critical error. Your plugin is installed, activated and jetpack too (sorry for my english, i’m french =) ).

    Thanks for your help !

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    It is indeed possible. Looking at the theme’s code, I see that the Blocksy theme comes with hooks you can use to inject content at different places in the theme.

    You could consequently add the following code snippet to a functionality plugin on your site to display the post views after the other post meta information in the grid view:

    add_filter( 'blocksy:archive:render-card-layer', function ( $output, $single_component) {
    	if ( 'post_meta' !== $single_component['id'] ) {
    		return $output;
    	}
    	$post_views = do_shortcode( '[jp_post_view]' );
    
    	$output = str_replace( '</li></ul>', '</li><li class="post-views">' . $post_views . '</li></ul>', $output );
    	return $output;
    }, 11, 2 );
    Thread Starter griselidis

    (@webmaster9280)

    Hi Jeremy,

    D’abord merci ! Thank you very much.

    It works perfecly with the grid view ??

    In the same way, do you know where i could find such “code lines” to add this information on single post page on top of post. With other metas like author, post date and metas ? I tried to add it with the shortcode in the customizer in metas taxonomie’s field but no success =) I knew it would not work but i wanted to test ??

    My english is horrible. Sorry ! And merci à nouveau

    Griselidis

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    In the same way, do you know where i could find such “code lines” to add this information on single post page on top of post.

    Yes, it works the same way. The hook name is different, but you can inject post views there as well. Here is how you would go about it:

    add_action( 'blocksy:post-meta:render-meta', function ( $single_meta_id ) {
    	/*
    	 * Only add the post views before a specific post meta.
    	 * Here we'll be adding it before the post date.
    	 */
    	if ( 'post_date' !== $single_meta_id ) {
    		return;
    	}
    
    	printf(
    		'<li class="meta-post-views">%s</li>',
    		do_shortcode( '[jp_post_view]' )
    	);
    }, 11, 1 );
    Thread Starter griselidis

    (@webmaster9280)

    i added it and it works like a charm =)

    Thank you again !

    I really appreciate your help and the way you help. As the php code is written, i see that i can move the meta post views to another place if needed.

    Have a good evening ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Way to display views in Blocksy post meta’ is closed to new replies.