Viewing 30 posts - 1 through 30 (of 32 total)
  • Author
    Posts
  • #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!

    #420057

    Hi 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!
    Ismael

    #459508

    Hi @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
    #461263

    Hi!

    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,
    Ismael

    #480778

    Hello 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,

    #481130

    Hi,

    That’s unexpected, can you please create us a WordPress administrator account? post it here as a private reply.

    Regards,
    Josue

    #481341

    Ok,

    Thanks Josue

    #481620

    Hi!

    Your code is different, you need to use something like get_the_tags but for categories, maybe get_the_terms could do it.

    Regards,
    Josue

    #621649

    I 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?

    #622932

    Hi,

    Can you post the link to your website please?

    Regards,
    Josue

    #645477

    Hi 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,
    Cheers

    #645510

    Hi,

    Can you post a link to the site? and also which of the code are you trying?

    Best regards,
    Josue

    #646170

    I 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

    #646815

    Hi,

    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,
    Josue

    #649214

    Hi 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

    #649452

    Can you post a link to the Page where you’re trying this? an admin account may be needed too.

    #649751

    Hi 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)

    #650528

    Hi,

    Can you please create us a WordPress administrator account? post it here as a private reply.

    Regards,
    Josue

    #650810

    Hi,

    yes no problem,
    your account has been created, you have got the login info in private,

    Thx !

    #651851

    Hi,

    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,
    Ismael

    #652001

    Hi Ismael !!

    Thanks you sooo much!!! it works like a charm !!!
    I love this theme and your support, all is possible :D
    Thanks a lottt

    Best Regards,
    Aztix

    #652505

    Hi Aztix,

    Great! Glad we could help and thanks for the kind words :-)

    Best regards,
    Rikard

    #801877

    i 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, 6 months ago by celebcomms.
    #802658

    Hi celebcomms,

    Here is how to get the link:

    If you need further assistance please let us know.
    Best regards,
    Victoria

    #851892

    Thanks 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

    #853642

    Hi,

    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,
    Ismael

    #970072

    Hello, Is there a code to add CATEGORY NAME above the TITLE in Masonry Blog. Display as centered overlay.

    Will appreciate quick reply

    Kind Regards

    #970536

    Hi 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-615662

    Best regards,
    Victoria

    #970966

    Hello 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 Team

    #971187

    Hi 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

Viewing 30 posts - 1 through 30 (of 32 total)
  • The topic ‘Post category in the mesonary blog’ is closed to new replies.