WordPress.org

Ready to get started?Download WordPress

Forums

WP Filter Reference for Templates page_template,template Hook (1 post)

  1. Mitchell McDeere
    Member
    Posted 3 years ago #

    I'm trying to eliminate alot of code from our templates and manage conditional statements that would appear within a specific template such as page.php , to my functions.php file. For example this appears at the top of my page.php template.

    get_header();
    $ancs=get_post_ancestors($post->ID);
    $parent=getPostParent($post->ID);
    if ( (isDest($post->ID)!=0) || (isDest($parent)!=0) || (in_array(29, $ancs))){
     	$dest=true;
     	//echo "2dest</br>";
    }else{
    
    	if (in_array(6292, $ancs) || $post->ID==6292){
    		$span=true;
    
    	}else{
    	//$dest=true;
    		//include("sideComBoxes.php");
    	}
    }

    Code critique aside..I was just wondering how I could execute this code from a WP Filter or Action when the page.php template is run?

    I looked into a few Filters such as :

    template
    applied to the template returned by the get_template function.

    So basically I would need a filter to add to the "template" hook and create a function with a conditional statement that will execute code only for a specific template?

    I understand the logistics. But Will this work and what object will I need from the global wordpress variables to see the template?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by Mitchell McDeere
  • This topic is not resolved
  • WordPress version: 3.0.5