Support » Fixing WordPress » Help writing a custom theme 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.


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


    Forum Moderator

    get_categories with the child_of parameter.

    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…

    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.