-
AuthorPosts
-
March 27, 2015 at 4:01 pm #419339
Hi!
There is a way to have the name of the post category in the mesonary blog? I don’t want to use the filter but I need to have the category name with title and excert, I’m sure that you have a solution ;)Thanks!
March 29, 2015 at 7:00 pm #420057Hi DavideModigliani!
Thank you for using Enfold.
Add this to the functions.php file:
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 == 'content' ) { $value .= "<div class='av-masonry-categories'>".$cat."</div>"; } $key[$post] = $value; } return $key; }
This will only work for default posts. If you want this to work for custom post types like the portfolio items, please hire a freelance developer.
Cheers!
IsmaelJune 15, 2015 at 5:12 pm #459508Hi @Ismael,
It is it possible for you to give the code to show the tags too?And when I use this code, it’s showing the category slug, not the name.
look: http://dev.freepresshost.com/scout/Thanks a lot for you soport!
- This reply was modified 9 years, 5 months ago by Freepress. Reason: Add more info
June 18, 2015 at 1:32 pm #461263Hi!
You can try this:
add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_loop_prepare_mod', 10, 2 ); function avf_masonry_loop_prepare_mod( $key, $entries ) { $posttags = get_the_tags($key['ID']); $taglist = array(); if ($posttags) { foreach($posttags as $tag) { $taglist[] = $tag->name; } } $tags = implode($taglist, ', '); foreach ( $key as $post => $value ) { if ( $post == 'content' ) { $value .= "<div class='av-masonry-categories'>".$tags."</div>"; } $key[$post] = $value; } return $key; }
Regards,
IsmaelJuly 30, 2015 at 4:52 pm #480778Hello Ismael,
The Code for show the categories on Masonry Blog its a perfect solution for, but, its showing the Category Slug insted the Category Name,
In the code what I need to change for it,
Thanks in advance,
Regards,
July 31, 2015 at 8:17 am #481130Hi,
That’s unexpected, can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
JosueJuly 31, 2015 at 2:48 pm #481341Ok,
Thanks Josue
August 1, 2015 at 4:41 am #481620Hi!
Your code is different, you need to use something like get_the_tags but for categories, maybe get_the_terms could do it.
Regards,
JosueApril 25, 2016 at 8:30 pm #621649I used this php to pull out the categories into the masonry element which is great thanks!
However, when the screen responds to being shown on mobile I have hidden the excerpt so it doesn’t get too cluttered. Is there a way to NOT also have it hide the categories? Looks like the <div> that the categories are show in are within the one the excerpt is shown in so am I out of luck?
April 27, 2016 at 11:33 am #622932Hi,
Can you post the link to your website please?
Regards,
JosueJune 9, 2016 at 3:29 pm #645477Hi team !
Thx for this really nice theme, i love it :)
I come back on this post because i want exatly the same thing as DavideModigliani,
I need to display categories title under each items portfolios titles !I tried to add your code to my function.php file, but the categories isn’t displaying.
When i look the code, i see this div :
<div class=”av-masonry-categories”></div>but he is empty :(
Do you know why the div is empty? is it possible that it’s because i use only item portfolios and not post ?
And how can i do that with item portfolios?Thx in advance,
CheersJune 9, 2016 at 4:02 pm #645510Hi,
Can you post a link to the site? and also which of the code are you trying?
Best regards,
JosueJune 10, 2016 at 1:12 pm #646170I tried the both code, and i now know why it doesn’t work,
I tried to change masonry type to call post and not item portfolios and your code works perfectly, but when i call my portfolios items the categorie don’t display !
Do you now how can i fix that?
My website si offline so and i can’t send you an address :(
Thx in advance
June 12, 2016 at 10:24 am #646815Hi,
Probably the portfolio items categories aren’t retrieved because they are a custom term, you need to change the function to work with this.
Best regards,
JosueJune 16, 2016 at 2:11 pm #649214Hi Team, thank you for your anwser !
I am sorry but i tried many things to adapt this function and i don’t manage to do what i want :(
can you help me to understand how it works please?
thx in advance,
Best regards,Aztix
June 16, 2016 at 11:36 pm #649452Can you post a link to the Page where you’re trying this? an admin account may be needed too.
June 17, 2016 at 1:02 pm #649751Hi Josue and thx anwsering me :)
I moved the website on a server, i give you in private the link
You will see in the code that i add <div class=’categorie’></div> in helper-masonry.php,
Thx in advance,
Best regards,Aztix
(sorry for my poor english)June 19, 2016 at 11:47 pm #650528Hi,
Can you please create us a WordPress administrator account? post it here as a private reply.
Regards,
JosueJune 20, 2016 at 2:13 pm #650810Hi,
yes no problem,
your account has been created, you have got the login info in private,Thx !
June 22, 2016 at 4:21 am #651851Hi,
Please use this code instead:
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_terms($key['ID'], 'portfolio_entries'); //var_dump($categories); $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,
IsmaelJune 22, 2016 at 10:36 am #652001Hi Ismael !!
Thanks you sooo much!!! it works like a charm !!!
I love this theme and your support, all is possible :D
Thanks a lotttBest Regards,
AztixJune 23, 2016 at 6:40 am #652505Hi Aztix,
Great! Glad we could help and thanks for the kind words :-)
Best regards,
RikardMay 31, 2017 at 8:42 am #801877i used below code and then i get my post category within masonry function.
but i want category link too.
how to get the category link?
add_filter( ‘avf_masonry_loop_prepare’, ‘post_category’);
function post_category( $key, $entries )
{
$categories = get_the_category($key[‘ID’]);
$separator = ‘ ‘;
$output = ‘<div class=”custom-masonry-cat”>’;
if ( ! empty( $categories ) ) {
foreach( $categories as $category ) {
$output .= esc_html( $category->name);
}
}
$output .= ‘</div>’;$key[‘text_before’] .= trim( $output, $separator );
return $key;
}- This reply was modified 7 years, 5 months ago by celebcomms.
June 1, 2017 at 4:57 pm #802658Hi celebcomms,
Here is how to get the link:
If you need further assistance please let us know.
Best regards,
VictoriaSeptember 14, 2017 at 7:59 am #851892Thanks reply #420057( second post from top) is working for me but can you please advise how I can get the Categories to display before the title instead of after the excerpt?
I just want to shuffle the order around
September 19, 2017 at 3:05 am #853642Hi,
i used below code and then i get my post category within masonry function.
I’m sorry but that’s not possible because the whole masonry item is already wrapped inside a link.
Best regards,
IsmaelJune 8, 2018 at 1:04 pm #970072Hello, Is there a code to add CATEGORY NAME above the TITLE in Masonry Blog. Display as centered overlay.
Will appreciate quick reply
Kind Regards
June 9, 2018 at 8:40 pm #970536Hi torahulparashar,
Could you please attach a mockup of what you’re trying to achieve?
Here is a thread for you to consider
https://kriesi.at/support/topic/inject-category-name-into-masonry-element/#post-615662Best regards,
VictoriaJune 11, 2018 at 8:03 am #970966Hello Victoria,
The code is working now. But the category is coming below the title. I need it above the title.
Here is the mock up that i want to achieve: http://prntscr.com/jti1r9
Here is what I got: http://prntscr.com/jti2bz
Will appreciate your quick reply.
Kind Regards
Credofy TeamJune 11, 2018 at 1:55 pm #971187Hi torahulparashar,
Try the code below:
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_before'] .= trim( $output, $separator ); return $key; }
Best regards,
Victoria -
AuthorPosts
- The topic ‘Post category in the mesonary blog’ is closed to new replies.