-
-
Save celsofabri/16d69aa8920757f749452ba200e65f8c to your computer and use it in GitHub Desktop.
Wordpress - Get the post terms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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