Get Sub-Category
-
I am trying to pull back a link and title of a post’s sub-category in a loop.
PARENTCAT1
-SUBCAT1
-SUBCAT2PARENTCAT2
-SUBCAT4
-SUBCAT51) I want to return a link and title. i.e.
<a href="http://site/cat/subcat4">SUBCAT4</a>
2) I would like to change the SUBCAT4 name on the link
3) I should be able to specify the PARENTCAT2 or 1This was kind of working, except I have to enter the category. I want it to use the category that the post is in and be able to only specify the PARENTCAT. A post will only be in ONE sub-category of the PARENTCAT
<?php // Get the ID of a given category $category_id = get_cat_ID( 'SUBCAT4' ); // Get the URL of this category $category_link = get_category_link( $category_id ); ?> <!-- Print a link to this category --> <a href="<?php echo $category_link; ?>" title="Category Name">SUBCAT4</a>I tried this also but it just brings back the PARENTCAT2
<?php // Get the category name $category_name = get_cat_name(5); // Get the ID of a given category $category_id = get_cat_ID( $category_name ); // Get the URL of this category $category_link = get_category_link( $category_id ); ?> <!-- Print a link to this category --> <a href="<?php echo $category_link; ?>" title="Category Name">SUBCAT4</a>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Get Sub-Category’ is closed to new replies.