Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #271725

    Hello guys.

    I’ve been trying to add only the associated categories and tags relating to individual portfolio items rather than ALL tags and categories .
    I’ve tried ‘Ultimate tag cloud widget’ http://wordpress.org/plugins/ultimate-tag-cloud-widget/ which allows the display of an item’s tags but it doesn’t work with the item’s categories for some reason.

    My workaround is to use a shortcode creator (http://wordpress.org/plugins/shortcodes-ui/) which allows you to create a shortcode to display certain things on a page, for example, to display the post title I have added ‘echo get_the_title($ID);’ into the PHP editor and created the shortcode ‘[post_title]’ which is then pasted into a text box.

    Can you please let me know what PHP code I would need to display an individual portfolio item’s categories and tags rather than all categories and tags.

    Many thanks.

    Robin

    #272260

    Hey AREA10STUDIO!

    You can use this code to query the portfolio categories of an entry:

    
                        $taxonomies  = get_object_taxonomies(get_post_type($ID));
                        $cats = '';
                        $excluded_taxonomies =  apply_filters('avf_exclude_taxonomies', array('post_tag','post_format'), get_post_type($ID), $ID);
    
                        if(!empty($taxonomies))
                        {
                            foreach($taxonomies as $taxonomy)
                            {
                                if(!in_array($taxonomy, $excluded_taxonomies))
                                {
                                    $cats .= get_the_term_list($ID, $taxonomy, '', ', ','').' ';
                                }
                            }
                        }
    
                        if(!empty($cats))
                        {
                            echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." ";
                            echo $cats;
                            echo '</span><span class="text-sep text-sep-cat">/</span>';
                        }
    
    

    and this code to display the tags:

    
                            $posttags = get_the_tags($ID);
                            if(!empty($posttags))
                            {
                                $taglinks = array();
                                foreach($posttags as $tag)
                                {
                                    $taglinks[] = '<a href="'. get_tag_link($tag->term_id) .'">'. $tag->name .'</a>';
                                }
    
                                if(!empty($taglinks))
                                {
                                    $taglinks = implode(",", $taglinks);
                                    $output .=  $taglinks;
                                }
                            }
    

    Regards,
    Peter

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.