/** * Display the page template * * @param string $template_name The template name * @param string $code Custom template code to use instead * @param object $obj The Pods object * @param bool $deprecated Whether to use deprecated functionality based on old function usage * * @return mixed|string|void * @since 2.0 */ public static function template($template_name, $code = null, $obj = null, $deprecated = false) { if (!empty($obj)) { self::$obj =& $obj; } else { $obj =& self::$obj; } self::$deprecated = $deprecated; if (empty($obj) || !is_object($obj)) { return ''; } $template = array('id' => 0, 'slug' => $template_name, 'code' => $code, 'options' => array()); if (empty($code) && !empty($template_name)) { $template_obj = $obj->api->load_template(array('name' => $template_name)); if (!empty($template_obj)) { $template = $template_obj; if (!empty($template['code'])) { $code = $template['code']; } $permission = pods_permission($template['options']); $permission = (bool) apply_filters('pods_templates_permission', $permission, $code, $template, $obj); if (!$permission) { return apply_filters('pods_templates_permission_denied', __('You do not have access to view this content.', 'pods'), $code, $template, $obj); } } } $code = apply_filters('pods_templates_pre_template', $code, $template, $obj); $code = apply_filters('pods_templates_pre_template_' . $template['slug'], $code, $template, $obj); ob_start(); if (!empty($code)) { // Only detail templates need $this->id if (empty($obj->id)) { while ($obj->fetch()) { echo self::do_template($code, $obj); } } else { echo self::do_template($code, $obj); } } elseif ($template_name == trim(preg_replace('/[^a-zA-Z0-9_\\-\\/]/', '', $template_name), ' /-')) { $default_templates = array('pods/' . $template_name, 'pods-' . $template_name, $template_name); $default_templates = apply_filters('pods_template_default_templates', $default_templates); if (empty($obj->id)) { while ($obj->fetch()) { pods_template_part($default_templates, compact(array_keys(get_defined_vars()))); } } else { pods_template_part($default_templates, compact(array_keys(get_defined_vars()))); } } $out = ob_get_clean(); $out = apply_filters('pods_templates_post_template', $out, $code, $template, $obj); $out = apply_filters('pods_templates_post_template_' . $template['slug'], $out, $code, $template, $obj); return $out; }
/** * Display the page template * * @see Pods_Templates::template * * @param string $template The template name * @param string $code Custom template code to use instead * @param bool $deprecated Whether to use deprecated functionality based on old function usage * * @return mixed Template output * * @since 2.0 * @link http://pods.io/docs/template/ */ public function template($template_name, $code = null, $deprecated = false) { $out = null; $obj =& $this; if (!empty($code)) { $code = str_replace('$this->', '$obj->', $code); // backwards compatibility $code = apply_filters('pods_templates_pre_template', $code, $template_name, $this); $code = apply_filters("pods_templates_pre_template_{$template_name}", $code, $template_name, $this); ob_start(); if (!empty($code)) { // Only detail templates need $this->id if (empty($this->id)) { while ($this->fetch()) { echo $this->do_magic_tags($code); } } else { echo $this->do_magic_tags($code); } } $out = ob_get_clean(); $out = apply_filters('pods_templates_post_template', $out, $code, $template_name, $this); $out = apply_filters("pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this); } elseif (class_exists('Pods_Templates')) { $out = Pods_Templates::template($template_name, $code, $this, $deprecated); } elseif ($template_name == trim(preg_replace('/[^a-zA-Z0-9_\\-\\/]/', '', $template_name), ' /-')) { ob_start(); $default_templates = array('pods/' . $template_name, 'pods-' . $template_name, $template_name); $default_templates = apply_filters('pods_template_default_templates', $default_templates); // Only detail templates need $this->id if (empty($this->id)) { while ($this->fetch()) { pods_template_part($default_templates, compact(array_keys(get_defined_vars()))); } } else { pods_template_part($default_templates, compact(array_keys(get_defined_vars()))); } $out = ob_get_clean(); $out = apply_filters('pods_templates_post_template', $out, $code, $template_name, $this); $out = apply_filters("pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this); } return $out; }
/** * Using fetch() with a specified ID to use pods for current item in the loop */ if (have_posts()) { //build pods find params //cache so this can be reused on each page of results //If not using persistent object caching, set 'cache_mode' => 'transient' $params = array('limit' => -1, 'expires' => DAY_IN_SECONDS); //build Pods object without specifying a Pod name //in Pods 2.4.1 or later pods() can figure out current post type or taxonomy, etc. on its own. $pods = pods(null, $params); // Start the Loop. while (have_posts()) { //put $post in a variable $post = the_post(); //fetch current item and store in $pods $pods = $pods->fetch($post->ID); //reset pods ID $pods->id = $post->ID; //include template part from theme //this is the equivalent of get_template_part( 'content', 'single' ); except $post and $pods are available for use in the template part now pods_template_part('content-single', compact(array('post', 'pods'))); //output a pods template of the same name as this Pod as well $template = $pods->template($pods->api->pod_data['name']); if ($template) { echo $template; } } //end wp loop } //end if have posts