WordPress Wednesdays: All Posts in a Parent Category

Web Development WordPress

The need to show all posts in a particular category or that category’s sub categories is very high. There are not too many projects out there that do not require a customized search, a menu, or a listing of some sort where the user wants to include all posts (or exclude) that belong to a parent category. Until recently – there was no real good way to do this. You either had to hard code category names or IDs in an array, or get really creative.

I recently started using the following function mentioned in the WordPress Codex that made this very easy: post_is_in_descendant_category().

By using that function – you can test to see if a post is in a particular category or even several subcategories deep of that category and then use that to easily show exactly what you want.

Examples and documentation for post_is_in_descendant_category: http://codex.wordpress.org/Template_Tags/in_category

Leave a Reply

Your email address will not be published.
*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Random

Linkfest Thursdays: May 14th Links

Here are some interesting links I have found in the last week or so. Hulu Most of you have heard of it, but if you have not checked it out yet – take a look. You will be impressed. No more excuses – just take a few minutes and check it out. Watchismo – I […]

CSS Hints HOWTOs

CSS Tuesday: Overide Inline Style

How many times have you worked with either someone else’s code or some crazy dynamically generated code that uses inline styles for everything which you need to change or override but cannot for some reason or another? I have seen this a lot with custom applications written by programmers who think they are doing designers […]