Advertisement
daymobrew

get_the_category() experiment

Jun 3rd, 2018
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: get_the_category experiment
  4. Plugin URI: https://www.damiencarbery.com
  5. Description: Experiment with get_the_category() function.
  6. Author: Damien Carbery
  7. Version: 0.1
  8. */
  9.  
  10. add_filter( 'the_content', 'append_get_the_category' );
  11. function append_get_the_category( $content ) {
  12. if ( !is_single() ) return $content;
  13.  
  14. $post_categories = get_the_category();
  15.  
  16. $categories = array();
  17. foreach ( $post_categories as $category ) {
  18. $categories[] = sprintf( '<a href="%s" class="cat-%s">%s</a>', esc_url( get_category_link( $category->term_id ) ), $category->slug, $category->name );
  19. }
  20. return $content . implode( ' ', $categories );
  21. }
  22.  
  23. /*
  24. WP_Term::__set_state(array(
  25. 'term_id' => 24,
  26. 'name' => 'Foo Parent',
  27. 'slug' => 'foo-parent',
  28. 'term_group' => 0,
  29. 'term_taxonomy_id' => 24,
  30. 'taxonomy' => 'category',
  31. 'description' => '',
  32. 'parent' => 0,
  33. 'count' => 1,
  34. 'filter' => 'raw',
  35. 'cat_ID' => 24,
  36. 'category_count' => 1,
  37. 'category_description' => '',
  38. 'cat_name' => 'Foo Parent',
  39. 'category_nicename' => 'foo-parent',
  40. 'category_parent' => 0,
  41. )),*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement