Make WordPress Core


Ignore:
Timestamp:
02/14/2012 03:54:46 AM (12 years ago)
Author:
lancewillett
Message:

Twenty Twelve template changes and fixes ... see #19978.

  • Add custom header support
  • header.php: use get_stylesheet_uri() to load stylesheet, props Mamaduka
  • Add full-width template, including adding relevant body_class value as a CSS hook
  • Hide sidebar on all views if no active widgets exist
  • Fix site title output (was missing site title)
  • Remove "featured" title for sticky posts
  • Add content template files for aside, image, link, and quote post formats
  • Indent content-single.php to match content.php
  • Remove sample JPG since Twenty Twelve ships with no default header images

... and style updates, props drewstrojny

  • Better footer styles
  • Styling for full-width layouts
  • Add basic styles for archive views
  • Refine post header/footer styles a bit
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentytwelve/functions.php

    r19845 r19915  
    3737add_action( 'after_setup_theme', 'twentytwelve_setup' );
    3838
    39 if ( ! function_exists( 'twentytwelve_setup' ) ):
     39if ( ! function_exists( 'twentytwelve_setup' ) ) :
    4040/**
    4141 * Sets up theme defaults and registers support for various WordPress features.
     
    6060    add_theme_support( 'automatic-feed-links' );
    6161
     62    // Add support for a variety of post formats
     63    add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote' ) );
     64
    6265    // This theme uses wp_nav_menu() in one location.
    6366    register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
    6467
    65     // Add support for custom backgrounds
     68    // Add support for custom background.
    6669    add_custom_background();
    67 }
     70
     71    // Add support for a custom header image.
     72    $header_args = array(
     73        'random-default' => true,
     74        'flex-height' => true,
     75        'suggested-height' => apply_filters( 'twentytwelve_header_image_height', 250 ),
     76        'flex-width' => true,
     77        'max-width' => apply_filters( 'twentytwelve_header_image_max_width', 2000 ),
     78        'suggested-width' => apply_filters( 'twentytwelve_header_image_width', 960 ),
     79    );
     80    add_theme_support( 'custom-header', $header_args );
     81    add_custom_image_header( 'twentytwelve_header_style', 'twentytwelve_admin_header_style', 'twentytwelve_admin_header_image' );
     82
     83    // The default header text color
     84    define( 'HEADER_TEXTCOLOR', '444' );
     85}
     86endif;
     87
     88if ( ! function_exists( 'twentytwelve_header_style' ) ) :
     89/**
     90 * Styles the header image and text displayed on the blog
     91 *
     92 * get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank'), or any hex value
     93 *
     94 * @since Twenty Twelve 1.0
     95 */
     96function twentytwelve_header_style() {
     97    // If no custom options for text are set, let's bail
     98    if ( HEADER_TEXTCOLOR == get_header_textcolor() )
     99        return;
     100    // If we get this far, we have custom styles.
     101    ?>
     102    <style type="text/css">
     103    <?php
     104        // Has the text been hidden?
     105        if ( 'blank' == get_header_textcolor() ) :
     106    ?>
     107        .site-title,
     108        .site-description {
     109            position: absolute !important;
     110            clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
     111            clip: rect(1px, 1px, 1px, 1px);
     112        }
     113    <?php
     114        // If the user has set a custom color for the text, use that.
     115        else :
     116    ?>
     117        .site-title a,
     118        .site-description {
     119            color: #<?php echo get_header_textcolor(); ?> !important;
     120        }
     121    <?php endif; ?>
     122    </style>
     123    <?php
     124}
     125endif;
     126
     127if ( ! function_exists( 'twentytwelve_admin_header_style' ) ) :
     128/**
     129 * Styles the header image displayed on the Appearance > Header admin panel.
     130 *
     131 * Referenced via add_custom_image_header() in twentytwelve_setup().
     132 *
     133 * @since Twenty Twelve 1.0
     134 */
     135function twentytwelve_admin_header_style() {
     136?>
     137    <style type="text/css">
     138    .appearance_page_custom-header #headimg {
     139        border: none;
     140    }
     141    #headimg h1,
     142    #headimg h2 {
     143        line-height: 1.6;
     144        margin: 0;
     145        padding: 0;
     146    }
     147    #headimg h1 {
     148        font-size: 30px;
     149    }
     150    #headimg h1 a {
     151        text-decoration: none;
     152    }
     153    #headimg h2 {
     154        font: normal 13px/1.8 "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
     155        margin-bottom: 24px;
     156    }
     157    #headimg img {
     158    }
     159    </style>
     160<?php
     161}
     162endif;
     163
     164if ( ! function_exists( 'twentytwelve_admin_header_image' ) ) :
     165/**
     166 * Custom header image markup displayed on the Appearance > Header admin panel.
     167 *
     168 * Referenced via add_custom_image_header() in twentytwelve_setup().
     169 *
     170 * @since Twenty Twelve 1.0
     171 */
     172function twentytwelve_admin_header_image() { ?>
     173    <div id="headimg">
     174        <?php
     175        if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
     176            $style = ' style="display:none;"';
     177        else
     178            $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
     179        ?>
     180        <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
     181        <h2 id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></h2>
     182        <?php $header_image = get_header_image();
     183        if ( ! empty( $header_image ) ) : ?>
     184            <img src="<?php echo esc_url( $header_image ); ?>" alt="" />
     185        <?php endif; ?>
     186    </div>
     187<?php }
    68188endif;
    69189
     
    90210        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    91211        'after_widget' => "</aside>",
    92         'before_title' => '<h3 class="widget-title">',
     212        'before_title' => '<h3 class="widget-title all-caps-title">',
    93213        'after_title' => '</h3>',
    94214    ) );
     
    108228        <nav id="<?php echo $nav_id; ?>">
    109229            <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
    110             <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
    111             <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
     230            <div class="nav-previous alignleft"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
     231            <div class="nav-next alignright"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
    112232        </nav><!-- #nav-above -->
    113233    <?php endif;
     
    203323}
    204324endif;
     325
     326/**
     327 * Extends the default WordPress body class to denote a full-width layout.
     328 *
     329 * Used in two cases: no active widgets in sidebar, and full-width page template.
     330 *
     331 * @since Twenty Twelve 1.0
     332 */
     333function twentytwelve_body_class( $classes ) {
     334    if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'full-width' ) )
     335        $classes[] = 'full-width';
     336
     337    return $classes;
     338}
     339add_filter( 'body_class', 'twentytwelve_body_class' );
Note: See TracChangeset for help on using the changeset viewer.