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

    Hi,

    As the title says, I simply want to display the post category above the title in masonry view. I’ve tried to edit the av-helper-masonry, but cant get my code to return the right results.

    Regards,

    Ash

    #658470

    Hey ashloudon,

    Would you mind posting us a screenshot/mockup of what you would like to achieve? You can upload the screenshot to imgur.com or dropbox and share the link here :)

    Best regards,
    Yigit

    #658482
    #660217

    Hi,

    Thank you for the screenshot. Please add this in the functions.php file:

    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 = '
    <div class="ww-masonry-cat">';
        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;
            }
        }
        $output .= '</div>
    ';
    
        $key['text_before'] .= trim( $output, $separator );
        return $key;
    }
    

    Best regards,
    Ismael

    #660244

    Ismael,

    That’s awesome! Thanks!

    Can I do the same thing with post date too?

    #660247

    Ismael,

    Cancel my last request – found it. For reference for other folk:

    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 = ' ';
        $date = get_the_date('d.m.y');
        
        
        $output = '
    <div class="ww-masonry-cat">';
        if ( ! empty( $categories ) ) {
            foreach( $categories as $category ) {
                $output .= '<span>' . esc_html( $category->name ) . '</span>' . $separator;
                $output .= '<span>' . esc_html( $date ) . '</span>' . $separator;
            }
        }
        
        $output .= '</div>
    ';
    
        $key['text_before'] .= trim( $output, $separator );
        return $key;
    }

    Cheers,

    Ash

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Display the post category above the title in masonry view’ is closed to new replies.