Display Parent Category Link on Child Category Page
-
I have a lot of nested categories and need to be able to display navigation links on the parent category pages to the child/sub categories, and a link back to the parent page from the child/sub category pages.
I would also like to be able to exclude parent and child links from select categories all together.
It would also be nice to include links to other child categories of the same parent. For instance I have Category A which has child categories A1 and A2. I would like to have a link on the A1 category page to A2 and a link to A1 on the A2 page. This however is of lowest priority.
Currently I am using this:
<!-- begin --> <?php //for this category on an archive page, get the ID $thisID = get_query_var('cat'); $get_children_cats = array( 'child_of' => $thisID //get children of this parent using the thisID variable from earlier ); //firstly, load data for your child category $child = get_category($thisID); //from your child category, grab parent ID $parent = $child->parent; //load object for parent category $parent_name = get_category($parent); //grab a category name $parent_name = $parent_name->name; echo '<strong><a href=" ' . get_category_link( $parent ) . ' ">' . $parent_name . '</a></strong><p>'; $child_cats = get_categories( $get_children_cats );//get children of this parent category foreach( $child_cats as $child_cat ){ //for each child category, get the ID $childID = $child_cat->cat_ID; echo '<strong> - <a href=" ' . get_category_link( $childID ) . ' ">' . $child_cat->name . '</a></strong>'; } //end of categories logic ?><p> <!-- end -->
This code does display the Parent and Child Category links but I would like to be able to include IF statements so I can have info like “Back To: <parent page link>” included ONLY on child pages and to be able to have text symbols appear between the child category links but NOT before or after the links (or not at all if there is only one child).
Unfortunately I don’t have enough programming or PHP to be successful with IF statements and would appreciate some advice.
- The topic ‘Display Parent Category Link on Child Category Page’ is closed to new replies.