开发者

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

Thank开发者_Python百科s, Azeem


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜