Advertisement
fahimmurshed

UAG: Link to Category in Post Grid Block

Feb 26th, 2021
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. // To display taxonomy (category) on the Post Grid block. For that, you need to use the following filter in your fucntions.php file of the child theme.
  2.  
  3. function single_post_title_before( $post_id, $attributes ) {
  4.     if( 'my-post-grid-class' == $attributes['className'] ){
  5.         $term_obj_list = get_the_terms( $post_id, 'category' );
  6.         // Get the id of category
  7.         $category_id = get_cat_ID( 'cat-4' );
  8.         // Get the URL of this category
  9.         $category_link = get_category_link( $category_id );
  10.         $link = '<a href="' .$category_link .'">' .$term_obj_list[0]->name.'</a>';
  11.         echo $link;
  12.     }
  13. }
  14. add_action( 'uagb_single_post_before_title_grid', 'single_post_title_before', 10, 2 );
  15.  
  16. // To apply different filters for a specific block you need to add a unique class to the block from the Advanced Tab of Post Grid Block. - https://imgur.com/qAye5Tn
  17. // Please refer to this screenshot - https://share.getcloudapp.com/v1uNPR0k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement