Skip to content

Instantly share code, notes, and snippets.

@celsofabri
Forked from cezarsmpio/functions.php
Created July 26, 2016 02:54
Show Gist options
  • Save celsofabri/16d69aa8920757f749452ba200e65f8c to your computer and use it in GitHub Desktop.
Save celsofabri/16d69aa8920757f749452ba200e65f8c to your computer and use it in GitHub Desktop.
Wordpress - Get the post terms
<?php
/**
* Get the terms of post
* @param object $p The post
* @param string $class CSS Class
* @param string $separator
* @return string The terms
*/
function get_post_terms($p, $class = 'post-preview__cat', $separator = '') {
$links = array();
$p->cats = wp_get_post_categories($p->ID);
foreach ($p->cats as $c) {
$cat = get_category($c);
$links[] = "<a href=\"" . get_category_link($cat->term_id) . "\" class=\"$class\">" . $cat->name . "</a>";
}
return implode($separator, $links);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment