Expand Cut Tags

No cut tags

Aug. 5th, 2008

branchandroot: oak against sky (Default)

So, as things stand, the WordPress Categories widget supports altering sort order, post count and dropdown vs. hierarchical display. But it does not support including or excluding categories.

There is a way around this, though, while we wait for it to show up in the core code! (Everyone thank Bricksmith for suggesting this work-around.)

First, you need to download, upload and activate the php-exec plugin. This plugin allows admins to put php code in an entry or widget and have WordPress recognize it as php and execute it instead of just treating it as plain text.

Next, you go to Design > Widgets and put the Text widget where you want the Categories to appear.

Into the Text widget you paste some variation on the following code:

<li id=”categories-1″ class=”widget-categories”>
<h2 class=”widgettitle”>Categories</h2>
<ul>
<?php wp_list_categories(’orderby=name&hierarchical=true&title_li=&exclude=76,77,78,79′); ?>
</ul>
</li>

Save that and voila, you have a pseudo Categories widget!

In my own case, I wanted to have two Categories widgets, the second one including all the categories that the first one excluded, so I pasted another copy into Text right under the first, with the ID “categories-2″ and the ‘exclude’ changed to ‘include’, and edited my CSS to add #categories-2 everywhere there was a #categories-1.

Caveats: 1) I do not know if it is possible to use this for a dropdown Categories, because that requires some Javascript and I have no idea whether that can be parsed inside a Text widget. 2) What you have is actually a widget inside a widget, codewise. The Categories widget is enclosed inside the li and div of the Text widget. This may cause problems with your CSS styling, depending on how it’s written. If your nested lists look like li li { rules }, this will probably cause problems. On the bright side, if you change it to ul ul { rules } that should fix the problem.

For a full list of the variables you can adjust in wp_list_categories, see the WP documentation.

September 2017

S M T W T F S
     12
3456789
10111213141516
1718 1920212223
24252627282930

Style Credit

Page generated Sep. 20th, 2017 02:33 pm
Powered by Dreamwidth Studios