Title: custom function with nested conditionals
Last modified: August 19, 2016

---

# custom function with nested conditionals

 *  [dooling](https://wordpress.org/support/users/dooling/)
 * (@dooling)
 * [17 years ago](https://wordpress.org/support/topic/custom-function-with-nested-conditionals/)
 * I use the Thesis Theme, but I’ll try to make this as generic as possible.
 * Basically I want to run html_code_1 if it’s a category page. That’s easy.
 * function custom_category_mmbox() {
    if (is_category()){ ?> <html_code_1> <?php}
 * /*But if it’s my home page, I want to check the MOST RECENT POST for a custom
   field, grab a value IF it’s there and run it. Otherwise, just run html_code_1.
   I’m a Python person. No matter what I do, I get bracket errors with this. Thanks
   for any help.*/
 * elseif(is_home()) {
 * /*This allegedly gets me the post_id of the most recent post. */
 * query_posts(‘showposts=1’);
    while (have_posts()) : the_post(); $post_id = $post-
   >ID;
 * /* Now see if it has a $key called “thesis_custom_code”
 * $key=”thesis_custom_code”;
    $mm_code = get_post_meta($post->ID, $key, true);
 * /* If it has such a key, echo the code */
 * { if($mm_code):
    echo $mm_code; }
 * /* If no custom field named thesis_custom_code, just run the first chunk of html_code_1*/
 * else:
    ?> <html_code_1> <?php } /* Thesis functions to hook the code in */ add_action(‘
   thesis_hook_multimedia_box’, ‘custom_category_mmbox’);

The topic ‘custom function with nested conditionals’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [dooling](https://wordpress.org/support/users/dooling/)
 * Last activity: [17 years ago](https://wordpress.org/support/topic/custom-function-with-nested-conditionals/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
