zeemy23
zeemy23

Reputation: 681

Wordpress PHP: List categories without links?

I am using wordpress 3.01, and would like to list a number of child categories within a parent in this format. Without links.

{ 'cat1' , 'cat2' }

Is this possible?

http://codex.wordpress.org/Template_Tags/wp_list_categories this call seems like the right one, but I can't figure out how to list them without turning off links

Thanks, Azeem

Upvotes: 0

Views: 5862

Answers (2)

supajb
supajb

Reputation: 487

You can do this by using the get_categories() function. This returns an array of all categories. There is a codex article on it here: http://codex.wordpress.org/Function_Reference/get_categories

$categories = get_categories();
$parent_id = 25; //the id of the parent category

foreach ($categories as $category) {
    if ($category->parent == $parent_id) {
        echo "'" . $category->name . "',"
    }
}

That should work - let me know how you go. Someone else might have a better solution but I've used similar solutions to this and it has worked without any problems.

Upvotes: 1

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107508

You could extend the Walker_Category class and assign it to the walker attribute in the $args for wp_list_categories($args);.

By doing this, you have the ability to override how the links are rendered. In your case, you could probably just copy the code from Walker_Category and remove the part that wraps the category name in an anchor (<a>).

Maybe there's an easier way; I don't know -- I'm a WP n00b.

Here is one example I scouted out for you:

http://www.wprecipes.com/how-to-modify-lists-like-categories-and-blogroll-in-wordpress

Upvotes: 0

Related Questions