• Hi guys.

    I am using the following code in my functions.php to link to multiple single pages some categories in my site. All these templates are stored in a folder as such wp-content/themes/mytheme/single

    /**
    * Define a constant path to our single template folder
    */
    define(SINGLE_PATH, TEMPLATEPATH . '/single');
    
    /**
    * Filter the single_template with our custom function
    */
    add_filter('single_template', 'my_single_template');
    
    /**
    * Single template function which will choose our template
    */
    function my_single_template($single) {
    	global $wp_query, $post;
    /**
    	* Checks for single template by category
    	* Check by category slug and ID
    	*/
    	foreach((array)get_the_category() as $cat) :
    
    		if(file_exists(SINGLE_PATH . 'single-' . $cat->slug . '.php'))
    			return SINGLE_PATH . '/single-' . $cat->slug . '.php';
    
    		elseif(file_exists(SINGLE_PATH . '/single-' . $cat->term_id . '.php'))
    			return SINGLE_PATH . '/single-' . $cat->term_id . '.php';
    
    	endforeach;
    	return $single;
    
    }

    I am also using this code in my header.php to create generate a unique css id for my body tag, depending which page template i use.
    <body id="<?php if (is_page_template('page-news.php')){echo "news";}elseif (is_page_template('page-contact.php')){ echo "contact";}else{echo "";}?>" >

    How can I get custom bg ids working on my multiple single.php pages?

    Help please.

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

The topic ‘Custom <body id=””> on multiple single.php’ is closed to new replies.