Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #979201

    Hi guys, Hope all are doing well.

    I have posted a question in this thread: https://kriesi.at/support/topic/post-category-in-the-mesonary-blog/

    But this seems to be closed now, so creating a new one.

    I got category on top of my post title, but when i give two categories, we need to add a comma in between. Can we show parent category first and its child after it.

    For example, in this screenshot: http://prntscr.com/k0o28e

    ‘Explore’ is parent category and others are child. As you can see in third one, child category is coming before the parent one. This is sorting Alphabetically.

    It will be great if you can help in this.

    Kind Regards
    Manpreet

    #980006

    Hey torahulparashar,

    Thank you for using Enfold.

    You should adjust the separator value.

    $separator = ', ';
    

    Add comma instead of space. Or replace the whole filter with this one.

    add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_loop_prepare_mod_cat', 10, 2 );
    function avf_masonry_loop_prepare_mod_cat( $key, $entries )
    {
        $categories = get_the_category($key['ID']);
        $separator = ', ';
    	$output = '';
    	$items = count($categories);
    	$i = 0;
        if ( ! empty( $categories ) ) {
            foreach( $categories as $category ) {
    			if($i++ === $items) {
    				$separator = '';
    			}
    			$output .= '<span alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</span>' . $separator;
            }
        }
        $key['text_before'] .= trim( $output, $separator );
    
        return $key;
    }

    Best regards,
    Ismael

    #980015

    Thankyou Ismael. It worked.

    Kind Regrads

    #980402

    Hi,

    Great, glad you got it working. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #980405

    Hello, It is working for now. Not sure about future if I need anything else in it. You can close the topic if you wish to.

    Kind Regards

    #980412

    Hey!

    Great! Glad we could help. We’ll close the thread now. :)

    Best regards,
    Ismael

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Post Category in Masonary Gallery’ is closed to new replies.