Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
July 8, 2016 at 12:59 pm #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
July 8, 2016 at 3:22 pm #658470Hey 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,
YigitJuly 8, 2016 at 3:41 pm #658482July 13, 2016 at 7:49 am #660217Hi,
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,
IsmaelJuly 13, 2016 at 10:10 am #660244Ismael,
That’s awesome! Thanks!
Can I do the same thing with post date too?
July 13, 2016 at 10:26 am #660247Ismael,
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
-
AuthorPosts
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.