Support » Themes and Templates » Dynamicly created classes for Categories

  • Dear mr/mrs,

    Im looking for a way to get a class for every single category dynamicly. Ive tried to implent this function:

    function the_category_unlinked($separator = ' ')
    { $categories = (array) get_the_category(); $thelist = ''; foreach($categories as $category)
    { // concate $thelist .= $separator . $category->category_nicename; } echo $thelist; }

    Ive followed the steps as explained by Lorelle And got it working apart from one bit. When u go to my site: You see at the right top the categories in a list with each category a different background. This works fine. But on the mid left of the page you see the Category name next to each post without any backgroundcolor. This is cause by the fact that the dynamic generated classes are not the the same for the categories in the list as for the category names placed next to the posts. Is it possible to dynimicly put the same cat# as class for the categorie names next to each post as the categorie list items? That would save a lot of manually css editing.


    The line I added to generate the classes for the category list items (in header.php):

    <div class="post<?php the_category_unlinked(' '); ?>">
    <?php wp_list_categories('hierarchical=false&title_li='); ?>

    The line I added to generate the class for the categorynames next to each post (in index.php):

    <div class="post<?php the_category_unlinked(' '); ?>">
    <?php the_category(' ') ?> </div>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Dynamicly created classes for Categories’ is closed to new replies.