• Resolved jcprovideo

    (@jcprovideo)


    What I need to do is set up a conditional statement that will determine whether a specific page template is used.

    For example something like this…but working of course LOL 🙂

    <?php if ( is_page_template(‘portfolio’)

    I could not find anything in the Codex regarding determining page template used. Any help would be appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jcprovideo

    (@jcprovideo)

    Oh the reason I am doing it this way is so that I don’t have to touch the PHP every time a ned page is added. Doing a standard if (is_page (‘portfolio’) would make me have to touch the PHP every time a new page is added.

    I found this code on a guys site. Gonna see if I can plug in it. Let me know if anyone else has any solutions.

    function is_page_template($template = 'portfolio.php') {
    	if (!is_page()) {
    		return false;
    	}
    
    	global $wp_query;
    
    	$page = $wp_query->get_queried_object();
    	$custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
    	$page_template = $custom_fields[0];
    
    	// We have no argument passed so just see if a page_template has been specified
    	if ( empty( $template ) ) {
    		if (!empty( $page_template ) ) {
    			return true;
    		}
    	} elseif ( $template == $page_template) {
    		return true;
    	}
    
    	return false;
    }

    >>I could not find anything in the Codex regarding determining page template used. <<

    Really?

    You’re looking for if(is_page()).

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    is_page_template() is built in, starting at 2.5 and up.

    http://codex.wordpress.org/Conditional_Tags#Is_a_Page_Template

    Thread Starter jcprovideo

    (@jcprovideo)

    Sweet…I was pretty close with my first guess. Thanks Otto42!

    doodlebee, I was referring to page template not page. is_page_template(‘portfolio.php’)

    Thanks All!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Conditional for Page template? if ( is_ page template’ is closed to new replies.