Need to display only primary category
Hi, I have "VIP ads" that have multiple categories (1,3,6) and I'd like to show on the homepage only the primary category and whenever someone picks some category (like 1 or 3 or 6) to show them that ads that we have an all categories with current name of cat. I mean the Ad have all categories, on homepage show only the Primary cat, on other categories show their cats (on cat 1 show "1", on cat 3 show "3" etc...).
I found in the wordpress forum the code
PHP Code:
function the_category( $separator = '', $parents = '', $post_id = false ) {
echo get_the_category_list( $separator, $parents, $post_id );
}
witch says that if Ill add
PHP Code:
$parents = 'single'
that should be fine, but when I change it, nothing happens.
I'v tested allso and that one on file
wp-content/themes/classipress/includes/actions.php line 163
PHP Code:
<?php the_category(', '); ?>
with this code:
PHP Code:
<?php $parentscategory ="";
foreach((get_the_category()) as $category) {
if ($category->category_parent == 0) {
$parentscategory .= ' <a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a>, ';
}
}
echo substr($parentscategory,0,-2); ?>
with no results.
Please Help.