I currently have this code that shows all the parent categories in a drop down list.
HTML/PHP Code
<ul>
<?php
$args = array(
'orderby' => 'name',
'hierarchical' => 1,
'taxonomy' => 'category',
'hide_empty' => 0,
'parent' => 0,
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a></li>';
}
?>
</ul>
There's no problem with the code below. Actually, it works perfectly! You can see it here at my wordpress website: www.bendaggers.com
What I want to achieve now is how can I add the 1st level child of the parent just what it shown in Image 1 below with the same effect.
Image 1 - Sample
This is what I want to achieve, whenever the user hovers on the listed Parent Category, it will display its 1st level child category as show in the image below.
Image 2 - Sample Parent/Category Hierarchy.
By the way, I need a working code PHP, HTML and CSS also.
I really appreciate you help and efforts, thank you very much!
Some additional Information that might be useful.
You can make function for check If the parent category has child category and pass parent term into newly created function. copy your ablove code and make a function and paste it in your custom function.
And get parent category(you should make first custom function to get paent term) and pass this term to your second custom function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With