WordPress.org

Ready to get started?Download WordPress

Forums

Dynamicly created classes for Categories (2 posts)

  1. stentec
    Member
    Posted 5 years ago #

    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: wdka.jonathansmits.nl 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.

    greetz,
    Jonathan

    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>
  2. stentec
    Member
    Posted 5 years ago #

    IS this post at the right forum?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.