Function Reference: geodir_locate_template

Summary

Locates template based on the template type.

Global Values

$post_type
(string) (required) The post type.

Default: None
$wp
(object) (required) WordPress object.

Default: None
$post
(object) (required) WordPress post object.

Default: None

Package

GeoDirectory

Parameters

$template
(string) (required) The template type.

Default: None

Return Values

(bool|string)
  • The template path.

Change Log

Since: 1.0.0

Source File

geodir_locate_template() is located in geodirectory-functions/template_functions.php [Line: 20]

Source Code

function geodir_locate_template($template = '')
{
    global $post_type, $wp, $post;
    $fields = array();

    switch ($template):
        case 'signup':
            return $template = locate_template(array("geodirectory/geodir-signup.php"));
            break;
        case 'add-listing':
            $gd_post_types = geodir_get_posttypes();
            
            if (!(!empty($post_type) && in_array($post_type, $gd_post_types))) {
                $post_type = '';
            }
            
            $sc_post_type = '';
            if (is_page() && !empty($post->post_content) && ($shortcode = geodir_parse_shortcodes($post->post_content, 'gd_add_listing'))) {
                $listing_page_id = $post->ID;
                if (!empty($shortcode['listing_type'])) {
                    $sc_post_type = $shortcode['listing_type'];
                }
            } else {
                $listing_page_id = geodir_add_listing_page_id();
            }
            
            $is_wpml = geodir_is_wpml() ? true : false;

            if ($listing_page_id != '' && (is_page($listing_page_id) || ($is_wpml && !empty($wp->query_vars['page_id']))) && isset($_REQUEST['listing_type'])
                && in_array($_REQUEST['listing_type'], $gd_post_types)) {
                $post_type = sanitize_text_field($_REQUEST['listing_type']);
            }
            
            if (empty($post_type) && !isset($_REQUEST['pid'])) {
                $pagename = $wp->query_vars['pagename'];
                
                if (!empty($gd_post_types)) {
                    $post_type = $gd_post_types[0];
                }
                
                if ($sc_post_type != '') {
                    $post_type = $sc_post_type;
                }
                
                if (empty($post_type) && !empty($gd_post_types)) {
                    $post_type = $gd_post_types[0];
                }
                
                if ($is_wpml && !empty($wp->query_vars['page_id'])) {
                    wp_redirect(geodir_getlink(get_permalink($wp->query_vars['page_id']), array('listing_type' => $post_type)));
                } else {
                    wp_redirect(trailingslashit(get_site_url()) . $pagename . '/?listing_type=' . $post_type);
                }
                gd_die();
            }
            return $template = locate_template(array("geodirectory/add-{$post_type}.php", "geodirectory/add-listing.php"));
            break;
        case 'success':
            $success_page_id = geodir_success_page_id();
            if ($success_page_id != '' && is_page($success_page_id) && isset($_REQUEST['listing_type'])
                && in_array($_REQUEST['listing_type'], geodir_get_posttypes())
            )
                $post_type = sanitize_text_field($_REQUEST['listing_type']);
            return $template = locate_template(array("geodirectory/{$post_type}-success.php", "geodirectory/listing-success.php"));
            break;
        case 'detail':
        case 'preview':
            if (in_array(get_post_type(), geodir_get_posttypes()))
                $post_type = get_post_type();
            return $template = locate_template(array("geodirectory/single-{$post_type}.php", "geodirectory/listing-detail.php"));
            break;
        case 'listing':
            $templates = array();
            if (is_post_type_archive() && in_array(get_post_type(), geodir_get_posttypes())) {
                $post_type = get_post_type();
                $templates[] = "geodirectory/archive-$post_type.php";
            }


            if (is_tax() && geodir_get_taxonomy_posttype()) {
                $query_obj = get_queried_object();
                $curr_taxonomy = isset($query_obj->taxonomy) ? $query_obj->taxonomy : '';
                $curr_term = isset($query_obj->slug) ? $query_obj->slug : '';
                $templates[] = "geodirectory/taxonomy-$curr_taxonomy-$curr_term.php";
                $templates[] = "geodirectory/taxonomy-$curr_taxonomy.php";
            }

            $templates[] = "geodirectory/geodir-listing.php";

            return $template = locate_template($templates);
            break;
        case 'information':
            return $template = locate_template(array("geodirectory/geodir-information.php"));
            break;
        case 'author':
            return $template = locate_template(array("geodirectory/geodir-author.php"));
            break;
        case 'search':
            return $template = locate_template(array("geodirectory/geodir-search.php"));
            break;
        case 'location':
            return $template = locate_template(array("geodirectory/geodir-location.php"));
            break;
        case 'geodir-home':
            return $template = locate_template(array("geodirectory/geodir-home.php"));
            break;
        case 'listing-listview':
            $template = locate_template(array("geodirectory/listing-listview.php"));
            if (!$template) {
                $template = geodir_plugin_path() . '/geodirectory-templates/listing-listview.php';
            }
            return $template;
            break;
        case 'widget-listing-listview':
            $template = locate_template(array("geodirectory/widget-listing-listview.php"));
            if (!$template) {
                $template = geodir_plugin_path() . '/geodirectory-templates/widget-listing-listview.php';
            }
            return $template;
            break;
		case 'email-message':
            $template = locate_template(array("geodirectory/email-message.php"));
            if (!$template) {
                $template = geodir_plugin_path() . '/geodirectory-templates/email-message.php';
            }
            return $template;
            break;
    endswitch;

    return false;

}