Changeset 1753

Show
Ignore:
Timestamp:
10/06/04 05:11:11 (4 years ago)
Author:
rboren
Message:

Page templates.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/admin-functions.php

    r1752 r1753  
    756756} 
    757757 
     758function get_page_templates() { 
     759    $themes = get_themes(); 
     760    $theme = get_current_theme(); 
     761    $templates = $themes[$theme]['Template Files']; 
     762    $page_templates = array(); 
     763 
     764    foreach ($templates as $template) { 
     765        $template_data = implode('', file(ABSPATH . $template)); 
     766        preg_match("|Template Name:(.*)|i", $template_data, $name); 
     767        preg_match("|Description:(.*)|i", $template_data, $description); 
     768 
     769        $name = $name[1]; 
     770        $description = $description[1]; 
     771 
     772        if (! empty($name)) { 
     773            $page_templates[trim($name)] = basename($template); 
     774        } 
     775    } 
     776 
     777    return $page_templates; 
     778} 
     779 
     780function page_template_dropdown($default = '') { 
     781    $templates = get_page_templates(); 
     782    foreach (array_keys($templates) as $template) : 
     783        if ($default == $templates[$template]) $selected = " selected='selected'"; 
     784        else $selected = ''; 
     785        echo "\n\t<option value='" . $templates[$template] . "' $selected>$template</option>"; 
     786        endforeach; 
     787} 
     788 
    758789function parent_dropdown($default = 0, $parent = 0, $level = 0) { 
    759790    global $wpdb; 
  • trunk/wp-admin/edit-page-form.php

    r1752 r1753  
    5050    </fieldset> 
    5151    <fieldset id="pageparent"> 
    52       <legend><?php _e('Page Parent') ?></a></legend>  
     52      <legend><?php _e('Page Parent') ?></legend>  
    5353      <div><select name="parent_id"> 
    54        <option value='0'>Main Page (no parent)</option> 
     54      <option value='0'><?php _e('Main Page (no parent)'); ?></option> 
    5555            <?php parent_dropdown($post_parent); ?> 
    5656        </select> 
     
    8080  <input name="referredby" type="hidden" id="referredby" value="<?php if (isset($_SERVER['HTTP_REFERER'])) echo htmlspecialchars($_SERVER['HTTP_REFERER']); ?>" /> 
    8181</p> 
     82 
     83<fieldset id="pageoptions"> 
     84     <legend><?php _e('Page Options') ?></legend>  
     85   <table width="100%" cellspacing="2" cellpadding="5" class="editform"> 
     86     <tr valign="top"> 
     87     <th scope="row"><?php _e('Page Template:') ?></th> 
     88   <td><div><select name="page_template"> 
     89     <option value='default'><?php _e('Default Template'); ?></option> 
     90     <?php page_template_dropdown($page_template); ?> 
     91     </select> 
     92     </div> 
     93     </td> 
     94     </tr> 
     95     </table> 
     96</fieldset> 
     97 
    8298<?php do_action('edit_page_form', ''); ?> 
    8399</form> 
  • trunk/wp-admin/edit-pages.php

    r1752 r1753  
    6969    $post_pingback = get_settings('default_pingback_flag'); 
    7070    $post_parent = 0; 
     71    $page_template = 'default'; 
    7172 
    7273    include('edit-page-form.php'); 
  • trunk/wp-admin/post.php

    r1752 r1753  
    201201    if ($post_status = 'static') { 
    202202        generate_page_rewrite_rules(); 
     203 
     204        add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true); 
    203205    } 
    204206 
     
    234236 
    235237        if ($post_status == 'static') { 
     238            $page_template = get_post_meta($post_ID, '_wp_page_template', true); 
     239 
    236240            include('edit-page-form.php'); 
    237241        } else { 
     
    439443    if ($post_status = 'static') { 
    440444        generate_page_rewrite_rules(); 
     445 
     446        if ( ! update_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'])) { 
     447            add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true); 
     448        } 
    441449    } 
    442450 
  • trunk/wp-blog-header.php

    r1726 r1753  
    216216            include("$wp_template_dir/single.php"); 
    217217            exit; 
    218         } else if (is_page() && 
    219                              file_exists("$wp_template_dir/page.php")) { 
    220             $wp_did_template_redirect = true; 
    221             include("$wp_template_dir/page.php"); 
     218        } else if (is_page() && file_exists(get_page_template())) { 
     219            $wp_did_template_redirect = true; 
     220            include(get_page_template()); 
    222221            exit; 
    223222        } else if (is_category() && 
  • trunk/wp-includes/functions.php

    r1752 r1753  
    448448} 
    449449 
    450 function get_post_meta($post_id, $key) { 
     450function get_post_meta($post_id, $key, $single = false) { 
    451451    global $wpdb, $post_meta_cache; 
    452452 
    453453    if (isset($post_meta_cache[$post_id][$key])) { 
    454         return $post_meta_cache[$post_id][$key]; 
     454        if ($single) { 
     455            return $post_meta_cache[$post_id][$key][0]; 
     456        } else { 
     457            return $post_meta_cache[$post_id][$key]; 
     458        } 
    455459    } 
    456460 
     
    464468    } 
    465469 
    466     return $values; 
     470    if ($single) { 
     471        if (count($values)) { 
     472            return $values[0]; 
     473        } else { 
     474            return ''; 
     475        } 
     476    } else { 
     477        return $values; 
     478    } 
    467479} 
    468480 
    469481function update_post_meta($post_id, $key, $value, $prev_value = '') { 
    470482    global $wpdb, $post_meta_cache; 
     483 
     484        if(! $wpdb->get_var("SELECT meta_key FROM $wpdb->postmeta WHERE meta_key 
     485= '$key' AND post_id = '$post_id'") ) { 
     486            return false; 
     487        } 
    471488 
    472489    if (empty($prev_value)) { 
     
    18211838} 
    18221839 
     1840function get_page_template() { 
     1841    global $wp_query; 
     1842 
     1843    $id = $wp_query->post->ID;   
     1844    $template_dir = get_template_directory(); 
     1845    $default = "$template_dir/page.php"; 
     1846 
     1847    $template = get_post_meta($id, '_wp_page_template', true); 
     1848 
     1849    if (empty($template) || ($template == 'default')) { 
     1850        return $default; 
     1851    } 
     1852 
     1853    if (file_exists("$template_dir/$template")) { 
     1854        return "$template_dir/$template"; 
     1855    } 
     1856 
     1857    return $default; 
     1858} 
     1859 
    18231860// Borrowed from the PHP Manual user notes. Convert entities, while 
    18241861// preserving already-encoded entities: