Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #608314

    I’m using the code to display the category.

    add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_loop_prepare_mod', 10, 2 );
    function avf_masonry_loop_prepare_mod( $key, $entries )
    {              
    	$class = preg_grep('/category/', $key['class']); 
        $getstr = str_replace('category-', '', implode(',', $class)); 
    	$categories = explode(',', $getstr);
    	$cat = implode(',', array_map('ucfirst', $categories));	
    	foreach ( $key as $post => $value ) {
    			if ( $post == 'the_title' ) { $value .= "<div class='av-masonry-categories'>".$cat."</div>"; }
    			$key[$post] = $value;
    	}
        return $key;
    }

    Two problems with the given code.
    1 – Its removing special chars like áéíóú
    2 – I would like to display above the title

    #609279

    i really dont feel that im getting the suport that i’ve paid for.
    Is this topic still active?

    #609426

    Hi,

    Please send us a temporary admin login so that we can have a closer look. You can post the details in the Private Content section of your reply.

    Regards,
    Rikard

    #609613
    #610914

    Hi!

    We are very sorry for the delay. The code above doesn’t really fetch the actual category of the posts. It utilizes the class attribute of the masonry items which contains the category name (ex: category-namehere). Please replace the code with this:

    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 = '';
        if ( ! empty( $categories ) ) {
            foreach( $categories as $category ) {
                $output .= '<span alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</span>' . $separator;
            }
        }
    
        $key['text_after'] .= trim( $output, $separator );
        return $key;
    }

    Best regards,
    Ismael

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.