Get categories for a post?
-
Hi, I’m creating a custom display of posts because we need it in a specific order and we need to color code the categories and it was too hard trying to customize the plugins I found out there.
I have everything working except the categories. I need to be able to list the categories before the post title and be able to assign each one an ID for color coding purposes (which I can do once I can figure out how to get the categories to display in the first place). I’ve tried wp_get_post_categories and wp_list_categories and at this point am back to square one with just the following that works (this works without categories):
function recent_posts_function($atts){
extract(shortcode_atts(array(
‘posts’ => 5,
), $atts));$return_string = ‘
- ‘;
query_posts(array(‘orderby’ => ‘date’, ‘order’ => ‘DESC’ , ‘showposts’ => $posts));
if (have_posts()) :
while (have_posts()) : the_post();$return_string .= ‘
-
‘.get_the_title().’
<img src=”/wp-content/uploads/2015/01/post-date.jpg” border=”0″ style=”float: left; padding-right:5px;”>’.get_the_date().’
‘;
endwhile;
endif;
$return_string .= ‘
‘;wp_reset_query();
return $return_string;
}function register_shortcodes(){
add_shortcode(‘kapitall-recent-posts’, ‘recent_posts_function’);
}add_action( ‘init’, ‘register_shortcodes’);
I’d appreciate any feedback on how to get categories pulled into this (there may be several categories for one post). Thanks in advance for any tips you can provide.
-
- The topic ‘Get categories for a post?’ is closed to new replies.