This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!
Status: not resolved
Tagged: category tag grid element
Viewing 2 reply threads
- AuthorPosts
- October 22, 2015 at 8:00 am #11817
Hello
I’m trying to add the coloured category tags in the grid elements, but I can’t find a way to do it. I’ve read the Visual Composer documentation but I can’t make it work
Currently my code is
add_filter( 'vc_grid_item_shortcodes', 'my_module_add_grid_shortcodes' ); function my_module_add_grid_shortcodes( $shortcodes ) { $shortcodes['vc_post_cat'] = array( 'name' => __( 'Post category', 'wpthms' ), 'base' => 'vc_post_cat', 'category' => __( 'Post', 'wpthms' ), 'description' => __( 'Show category label', 'wpthms' ), 'post_type' => Vc_Grid_Item_Editor::postType(), ); return $shortcodes; } // output function add_shortcode( 'vc_post_cat', 'vc_post_cat_render' ); function vc_post_cat_render() { global $post; $categories = get_the_category($post->ID ); $category = $categories[0]; $cat_tag .= '<span class="entry-category">'; $cat_tag .= '<a class="cat-tag ' . esc_attr( $category->slug ) . '" href="'. esc_attr( get_category_link( $category->term_id ) ) .'" title="' . esc_attr( sprintf( __( 'View all posts in %s', 'wpthms' ), $category->name ) ) . '">'.$category->cat_name.'</a>'; $cat_tag .= '</span>'; //$class .= ' category-' . $category->slug; return $cat_tag; }
- This topic was modified 6 y, 6 mo by
denisslef.
- This topic was modified 6 y, 6 mo by
denisslef.
- This topic was modified 6 y, 6 mo by
- October 26, 2015 at 11:20 am #11837
Ok I finally found a solution, I post it here.
Solution is to add meta to post according to their categories
add_action( 'save_post', 'add_meta_cat_on_post_save' ); function add_meta_cat_on_post_save($post_id){ global $post, $current_user; if( !current_user_can( 'manage_options' ) ) return; $catID = $_POST['post_category'][1]; $categories = get_category( $catID ); if( !empty( $categories )) { $category = $categories; $cat_tag = '<span class="entry-category">'; $cat_tag .= '<a>slug ) . '" href="'. esc_attr( get_category_link( $category->term_id ) ) .'" title="' . esc_attr( sprintf( __( 'View all posts in %s', 'wpthms' ), $category->name ) ) . '">'.$category->cat_name.'</a>'; $cat_tag .= '</span>'; update_post_meta ( $post_id, 'cat-tag', $cat_tag ); } }
- October 30, 2015 at 4:59 pm #11861
Hey there, You must be logged in to view this reply!
- AuthorPosts
Viewing 2 reply threads
- You must be logged in to reply to this topic.
This is a PRIVATE forum for verified users only, to view all replies/answers, you must be logged in!