Title: Help writing a custom theme function
Last modified: August 20, 2016

---

# Help writing a custom theme function

 *  [pshero](https://wordpress.org/support/users/pshero/)
 * (@pshero)
 * [15 years ago](https://wordpress.org/support/topic/help-writing-a-function/)
 * Ok, so I know what I need to do, but I’m not awesome at PHP and could use a hand
   if any of you Gurus have a spare second.
 * In my theme admin I’ve written an option where the user can select a Parent Category
   for Photography and what I want to do is create a function that will take that
   parent and create a coma separated list of the parent and it’s children as category
   ID’s so that I can plug in the function call to an if statement in any of my 
   template pages to call custom classes.
 * So the function needs to go like this:
 * Get the custom option for my_photography_catgory and check if it has children,
   if so, create a list of coma separated category ID’s into an array so the output
   would look like array(1, 3, 5, 6)
 * If anyone can help me out here I’d GREATLY appreciate it.
 * Thanks!!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/help-writing-a-function/#post-2108799)
 * [get_categories](http://codex.wordpress.org/Function_Reference/get_categories)
   with the child_of parameter.
 *  Thread Starter [pshero](https://wordpress.org/support/users/pshero/)
 * (@pshero)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/help-writing-a-function/#post-2108952)
 * Thanks esmi, was hoping for a little more than a codex reference, but I’ll do
   some digging in that direction and see if I can find some code to repurpose…
 *  Thread Starter [pshero](https://wordpress.org/support/users/pshero/)
 * (@pshero)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/help-writing-a-function/#post-2109046)
 * Ok, I’ve got this started, but for some reason the logic isn’t working and I 
   can’t figure out why… can anyone see where I’ve gone wrong here? the options 
   are set correctly through the admin panel and have been tested successfully.
 *     ```
       $mycat = 'post';
       $photocat = get_option('my_photography_category');
       $quotecat = get_option('my_quotation_category');
       $quotecatID = get_cat_ID( $quotecat );
       if (get_categories('child_of => $photocat', TRUE)) {
           $mycat = 'photograph';
       }
       if (in_category($quotecatID)) {
           $mycat = 'quote';
       }
       ```
   
 * Also, I’d love a way to do this in the functions.php file so that all I have 
   to do is call $mycat and it’d post the correct content.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Help writing a custom theme function’ is closed to new replies.

## Tags

 * [PHP functions](https://wordpress.org/support/topic-tag/php-functions/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [pshero](https://wordpress.org/support/users/pshero/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/help-writing-a-function/#post-2109046)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
