0

I'm building a website in which there is a navigation menu with various links; in this menu there is the link to the blog section. My goal is to create a drop down menu that appears when the cursor is passed over the blog link; this link has to show the list of the categories.

A few days ago I found this useful tutorial:

But it creates another link called "Categories" in which appears the categories drop down menu; therefore how can I adapt that code in my case?

1 Answer 1

0

You have to modify only the first part as this:

<ul id="nav" class="clearfloat">
<li class="cat-item"><a href="<?php echo get_option('home'); ?>/" class="on"><?php echo get_option('blogname'); ?></a>
<ul class="children">
<?php wp_list_categories('orderby=name&title_li=');
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
echo "<ul>";
wp_list_categories('orderby=id&show_count=0&title_li=
&use_desc_for_title=1&child_of='.$this_category->cat_ID);
echo "</ul>";
}
?>
</ul>
</li>
<?php wp_list_pages('title_li='); ?>
</ul>

Here the menu will show up when you pass the cursor over the name of the blog that will be the first entry of the menu. If you want to show "home" and not the blog name just substitute

<?php echo get_option('blogname'); ?>

with

Home

If you want to show up not in the menu but in the logo of your blog page, just leave the menu code as the original one in wordpress, and substitute the code of the link you want to add the menu with this:

<ul id="nav" class="clearfloat">
    <li class="cat-item"><a href="<put here the old reference of the link you are substituting>/" class="on"><put here the old content (maybe an image?, everything you found between the a>xxx<\a> tags) of the link you are substituting></a>
    <ul class="children">
    <?php wp_list_categories('orderby=name&title_li=');
    $this_category = get_category($cat);
    if (get_category_children($this_category->cat_ID) != "") {
    echo "<ul>";
    wp_list_categories('orderby=id&show_count=0&title_li=
    &use_desc_for_title=1&child_of='.$this_category->cat_ID);
    echo "</ul>";
    }
    ?>
    </ul>
    </li>
    </ul>

Hope this helps, Marco

3
  • Thanks for the response! I'll try and I'll let you know if it works.
    – DamianFox
    Jul 27, 2013 at 10:26
  • I have tried to use your code but every link in the navigation bar disappear except the one that show the drop down menu.
    – DamianFox
    Jul 27, 2013 at 14:11
  • For the second one is correct, for the first one you should visualize avery link, if you want all the links just add <?php wp_list_pages('title_li='); ?> before the last </ul> Jul 31, 2013 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.