Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Advanced Wordpress

  • 29-07-2009 12:42AM
    #1
    Registered Users, Registered Users 2 Posts: 28


    Hi all,

    In a bit if a rut with a site i am currently putting together in Wordpress.
    Using version 2.7 as 2.8+ is still full of bugs.
    Anyway, i am using the Categories for navigation in a horizontal bar across the top of the site.
    I need to display the category description in a hoverbox when the user 'hovers' over the category.
    I know how to create a hoverbox for text or pictures on a static page but as the Category navigation code is being genterated by Wordpress, i dont know how i would go about creating a hoverbox for each individual category.

    Or even doesn anyone know if there is a plugin out there that will do this?
    I know that one is a long shot but worth a try.

    I know that some templates provide a hoverbox for the category description but the template i'm using (WooThemes NewsPress) doesnt.
    I have tried looking within templates that do provide the hoverbox feature for the code that generates this but as of yet, i have had no luck.

    Any help would be greatly appriciated!

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    by hover box do you just mean, like a tool tip?

    post code bit where categories are specified, would be in your header/top nav part


  • Closed Accounts Posts: 122 ✭✭Tarzan_man


    All you really need to do is add <?php echo category_description( $category ); ?> to the title attribute of each link. So like this:
    <a href="whatever-the-link-is" class="whatever-the-class-is" title="<?php echo category_description( $category ); ?>" >Category </a>
    

    $category should be the ID of the category you wish to get the description of.

    Eg. <?php echo category_description('2'); ?> if you wanted to display the description of category 2. You can get the category IDs by hovering over the names of the categorys in wordpress's backend.


  • Registered Users, Registered Users 2 Posts: 28 rochemedia


    Hi Tarzan_man,

    Thanks for the info. I understand the logic of what you are describing and i can follow it, however my <a href> links are generated by Wordpress by using php to get a list of Categories.
    I cant see how to fit in your code with this code. Here is the code generating the <a href's

    <div di="catnav">
    <ul class="nav2">
    <?php wp_list_categories('title_li=') ?>
    </ul>
    </div>

    Any idea where to go from that?

    Thanks


  • Registered Users, Registered Users 2 Posts: 576 ✭✭✭pts


    I think what you need to do is use the get_all_category_ids function, which returns an array of ids.

    Then iterate through the array passing down the current id as a parameter to functions such as get_cat_name( $cat_id ) to get the name, get_category_link( $category_id ) to get the link etc. Then use this information to construct the html links.

    EDIT: got bored so thought I might as well do up the code. This is from the top of my head, so there might be mistakes in it.
    <div di="catnav">
    <ul class="nav2">
    <?php 
    $ids = get_all_category_ids();
    
    for($i = 0; $i < sizeof($ids); $i++)
    {
        $link = get_category_link($ids[i]);
        $name = get_cat_name($ids[i]);
        $desc= category_description($ids[i]);
    
        echo "<li><a href=$link class='whatever-the-class-is' title='$desc' >$name  </a></li>";
    }
    
    ?>
    </ul>
    </div>
    


  • Registered Users, Registered Users 2 Posts: 28 rochemedia


    Thanks PTS & Tarzan_man

    With a bit of tweaking i was able to get this working.
    Did the job great!

    I owe ya one! :cool:


  • Advertisement
Advertisement