WordPress.org

Ready to get started?Download WordPress

Forums

Categories list PHP help (3 posts)

  1. kortschot
    Member
    Posted 2 years ago #

    Hi there,

    My PHP skills are (still) not what I like them to be, so I was wondering if somebody could help me out here.

    In the end I need this:

    <ul id="filters">
       <li><a href="#" data-filter=".[category-name-here]">green</a>[category-name-here]</li>
    </ul>

    I want to accomplish this with listing the categories from WordPress.

    So i.e. I got Categories: Blue, Green and Lovely Pinkish in WP backend, the source will show:

    <ul id="filters>
      <li><a href="#" data-filter=".blue">Blue</a></li>
      <li><a href="#" data-filter=".green">Green</a></li>
      <li><a href="#" data-filter=".lovely-pinkish">Lovely Pinkish</a></li>
    </ul>

    Blue, green and lovely-pinkish being WP categories.

    What I got up with is this:

    <a href="#" data-filter=".<?php $category = get_the_category(); echo $category[0]->cat_name; ?>"><?php wp_list_categories(); ?></a>

    Not working so much I'm afraid.

    Help is much appreciated.

    Thanks in advance, with kind regards,
    Paul

  2. kortschot
    Member
    Posted 2 years ago #

    Im still looking in to this, so when somebody has something to add, please don't hesitate to do so.

  3. kortschot
    Member
    Posted 2 years ago #

    this just came to mind....

    <?php
    foreach((get_the_category()) as $category) {
        echo '
    <li><a href="#">cat_name . '">' . $category->cat_name .'</a></li>
    ' ;
      }
    ?>

    Can't test it out atm, does this look like a feasible solution?
    Think I'm messing up all the points and apostrophes in the PHP.

Topic Closed

This topic has been closed to new replies.

About this Topic