WordPress.org

Make WordPress Core

Changeset 13146


Ignore:
Timestamp:
02/14/2010 09:32:23 AM (10 years ago)
Author:
westi
Message:

Introduce new get_generic_template() function for themes to use to bring in pieces of template.
Use in twentyten for loop.php including. See #9015.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyten/archive.php

    r13141 r13146  
    1818<?php rewind_posts(); ?>
    1919
    20 <?php include 'loop.php'; ?>
     20<?php get_generic_template( 'loop', 'archive' ); ?>
    2121
    2222            </div><!-- #content -->
  • trunk/wp-content/themes/twentyten/author.php

    r13141 r13146  
    2222<?php rewind_posts(); ?>
    2323
    24 <?php include 'loop.php'; ?>
     24<?php get_generic_template( 'loop', 'author' ); ?>
    2525
    2626            </div><!-- #content -->
  • trunk/wp-content/themes/twentyten/category.php

    r13141 r13146  
    1111<?php rewind_posts(); ?>
    1212
    13 <?php include 'loop.php'; ?>
     13<?php get_generic_template( 'loop', 'category' ); ?>
    1414
    1515            </div><!-- #content -->
  • trunk/wp-content/themes/twentyten/index.php

    r13141 r13146  
    55
    66    <?php if ( have_posts() ) :
    7         include 'loop.php';
     7        get_generic_template( 'loop', 'index' );
    88    else : ?>
    99        <h2><?php _e( 'Not Found', 'twentyten' ); ?></h2>
  • trunk/wp-content/themes/twentyten/search.php

    r13141 r13146  
    66<?php if ( have_posts() ) : ?>
    77                <h1 class="page-title"><?php _e( 'Search Results for: ', 'twentyten' ); ?><span><?php the_search_query(); ?></span></h1>
    8     <?php include 'loop.php'; ?>
     8    <?php get_generic_template( 'loop', 'search' ); ?>
    99<?php else : ?>
    1010                <div id="post-0" class="post no-results not-found">
  • trunk/wp-content/themes/twentyten/tag.php

    r13141 r13146  
    1010<?php rewind_posts(); ?>
    1111
    12 <?php include 'loop.php'; ?>
     12<?php get_generic_template( 'loop', 'tag' ); ?>
    1313
    1414            </div><!-- #content -->
  • trunk/wp-includes/general-template.php

    r13143 r13146  
    9292    if ('' == locate_template($templates, true))
    9393        load_template( get_theme_root() . '/default/sidebar.php');
     94}
     95
     96/**
     97 * Load a generic template.
     98 *
     99 * Includes the named template for a theme or if a name is specified then a
     100 * specialised template will be included. If the theme contains no {slug}.php file
     101 * then no template will be included.
     102 *
     103 * For the parameter, if the file is called "{slug}-special.php" then specify
     104 * "special".
     105 *
     106 * @uses locate_template()
     107 * @since 3.0.0
     108 * @uses do_action() Calls 'get_generic_template_{$slug}' action.
     109 *
     110 * @param string $slug The slug name for the generic template.
     111 * @param string $name The name of the specialised template.
     112 */
     113function get_generic_template( $slug, $name = null ) {
     114    do_action( "get_generic_template_{$slug}", $name );
     115
     116    $templates = array();
     117    if ( isset($name) )
     118        $templates[] = "{$slug}-{$name}.php";
     119
     120    $templates[] = "{$slug}.php";
     121
     122    locate_template($templates, true);
    94123}
    95124
Note: See TracChangeset for help on using the changeset viewer.