Created
June 28, 2012 23:23
-
-
Save evansmith/3014688 to your computer and use it in GitHub Desktop.
this is functions.php. it's only adding one field, but on test runs in the html it works. starts at *image meta boxes*
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Twenty Eleven functions and definitions | |
* | |
* Sets up the theme and provides some helper functions. Some helper functions | |
* are used in the theme as custom template tags. Others are attached to action and | |
* filter hooks in WordPress to change core functionality. | |
* | |
* The first function, twentyeleven_setup(), sets up the theme by registering support | |
* for various features in WordPress, such as post thumbnails, navigation menus, and the like. | |
* | |
* When using a child theme (see http://codex.wordpress.org/Theme_Development and | |
* http://codex.wordpress.org/Child_Themes), you can override certain functions | |
* (those wrapped in a function_exists() call) by defining them first in your child theme's | |
* functions.php file. The child theme's functions.php file is included before the parent | |
* theme's file, so the child theme functions would be used. | |
* | |
* Functions that are not pluggable (not wrapped in function_exists()) are instead attached | |
* to a filter or action hook. The hook can be removed by using remove_action() or | |
* remove_filter() and you can attach your own function to the hook. | |
* | |
* We can remove the parent theme's hook only after it is attached, which means we need to | |
* wait until setting up the child theme: | |
* | |
* <code> | |
* add_action( 'after_setup_theme', 'my_child_theme_setup' ); | |
* function my_child_theme_setup() { | |
* // We are providing our own filter for excerpt_length (or using the unfiltered value) | |
* remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); | |
* ... | |
* } | |
* </code> | |
* | |
* For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API. | |
* | |
* @package WordPress | |
* @subpackage Twenty_Eleven | |
* @since Twenty Eleven 1.0 | |
*/ | |
/** | |
* Set the content width based on the theme's design and stylesheet. | |
*/ | |
if ( ! isset( $content_width ) ) | |
$content_width = 584; | |
/** | |
* Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run. | |
*/ | |
add_action( 'after_setup_theme', 'twentyeleven_setup' ); | |
if ( ! function_exists( 'twentyeleven_setup' ) ): | |
/** | |
* Sets up theme defaults and registers support for various WordPress features. | |
* | |
* Note that this function is hooked into the after_setup_theme hook, which runs | |
* before the init hook. The init hook is too late for some features, such as indicating | |
* support post thumbnails. | |
* | |
* To override twentyeleven_setup() in a child theme, add your own twentyeleven_setup to your child theme's | |
* functions.php file. | |
* | |
* @uses load_theme_textdomain() For translation/localization support. | |
* @uses add_editor_style() To style the visual editor. | |
* @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats. | |
* @uses register_nav_menus() To add support for navigation menus. | |
* @uses add_custom_background() To add support for a custom background. | |
* @uses add_custom_image_header() To add support for a custom header. | |
* @uses register_default_headers() To register the default custom header images provided with the theme. | |
* @uses set_post_thumbnail_size() To set a custom post thumbnail size. | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_setup() { | |
/* Make Twenty Eleven available for translation. | |
* Translations can be added to the /languages/ directory. | |
* If you're building a theme based on Twenty Eleven, use a find and replace | |
* to change 'twentyeleven' to the name of your theme in all the template files. | |
*/ | |
load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' ); | |
$locale = get_locale(); | |
$locale_file = get_template_directory() . "/languages/$locale.php"; | |
if ( is_readable( $locale_file ) ) | |
require_once( $locale_file ); | |
// This theme styles the visual editor with editor-style.css to match the theme style. | |
add_editor_style(); | |
// Load up our theme options page and related code. | |
require( get_template_directory() . '/inc/theme-options.php' ); | |
// Grab Twenty Eleven's Ephemera widget. | |
require( get_template_directory() . '/inc/widgets.php' ); | |
// Add default posts and comments RSS feed links to <head>. | |
add_theme_support( 'automatic-feed-links' ); | |
// This theme uses wp_nav_menu() in one location. | |
register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) ); | |
// Add support for a variety of post formats | |
add_theme_support( 'post-formats', array( 'gallery' ) ); | |
// Add support for custom backgrounds | |
add_custom_background(); | |
// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images | |
add_theme_support( 'post-thumbnails' ); | |
// The next four constants set how Twenty Eleven supports custom headers. | |
// The default header text color | |
define( 'HEADER_TEXTCOLOR', '000' ); | |
// By leaving empty, we allow for random image rotation. | |
define( 'HEADER_IMAGE', '' ); | |
// The height and width of your custom header. | |
// Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values. | |
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) ); | |
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) ); | |
// We'll be using post thumbnails for custom header images on posts and pages. | |
// We want them to be the size of the header image that we just defined | |
// Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. | |
set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); | |
// Add Twenty Eleven's custom image sizes | |
add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images | |
add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist | |
// Turn on random header image rotation by default. | |
add_theme_support( 'custom-header', array( 'random-default' => true ) ); | |
// Add a way for the custom header to be styled in the admin panel that controls | |
// custom headers. See twentyeleven_admin_header_style(), below. | |
add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' ); | |
// ... and thus ends the changeable header business. | |
// Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. | |
register_default_headers( array( | |
'wheel' => array( | |
'url' => '%s/images/headers/wheel.jpg', | |
'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Wheel', 'twentyeleven' ) | |
), | |
'shore' => array( | |
'url' => '%s/images/headers/shore.jpg', | |
'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Shore', 'twentyeleven' ) | |
), | |
'trolley' => array( | |
'url' => '%s/images/headers/trolley.jpg', | |
'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Trolley', 'twentyeleven' ) | |
), | |
'pine-cone' => array( | |
'url' => '%s/images/headers/pine-cone.jpg', | |
'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Pine Cone', 'twentyeleven' ) | |
), | |
'chessboard' => array( | |
'url' => '%s/images/headers/chessboard.jpg', | |
'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Chessboard', 'twentyeleven' ) | |
), | |
'lanterns' => array( | |
'url' => '%s/images/headers/lanterns.jpg', | |
'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Lanterns', 'twentyeleven' ) | |
), | |
'willow' => array( | |
'url' => '%s/images/headers/willow.jpg', | |
'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Willow', 'twentyeleven' ) | |
), | |
'hanoi' => array( | |
'url' => '%s/images/headers/hanoi.jpg', | |
'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg', | |
/* translators: header image description */ | |
'description' => __( 'Hanoi Plant', 'twentyeleven' ) | |
) | |
) ); | |
} | |
endif; // twentyeleven_setup | |
if ( ! function_exists( 'twentyeleven_header_style' ) ) : | |
/** | |
* Styles the header image and text displayed on the blog | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_header_style() { | |
// If no custom options for text are set, let's bail | |
// get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value | |
if ( HEADER_TEXTCOLOR == get_header_textcolor() ) | |
return; | |
// If we get this far, we have custom styles. Let's do this. | |
?> | |
<style type="text/css"> | |
<?php | |
// Has the text been hidden? | |
if ( 'blank' == get_header_textcolor() ) : | |
?> | |
#site-title, | |
#site-description { | |
position: absolute !important; | |
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ | |
clip: rect(1px, 1px, 1px, 1px); | |
} | |
<?php | |
// If the user has set a custom color for the text use that | |
else : | |
?> | |
#site-title a, | |
#site-description { | |
color: #<?php echo get_header_textcolor(); ?> !important; | |
} | |
<?php endif; ?> | |
</style> | |
<?php | |
} | |
endif; // twentyeleven_header_style | |
if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : | |
/** | |
* Styles the header image displayed on the Appearance > Header admin panel. | |
* | |
* Referenced via add_custom_image_header() in twentyeleven_setup(). | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_admin_header_style() { | |
?> | |
<style type="text/css"> | |
.appearance_page_custom-header #headimg { | |
border: none; | |
} | |
#headimg h1, | |
#desc { | |
font-family: "Helvetica Neue", Arial, Helvetica, "Nimbus Sans L", sans-serif; | |
} | |
#headimg h1 { | |
margin: 0; | |
} | |
#headimg h1 a { | |
font-size: 32px; | |
line-height: 36px; | |
text-decoration: none; | |
} | |
#desc { | |
font-size: 14px; | |
line-height: 23px; | |
padding: 0 0 3em; | |
} | |
<?php | |
// If the user has set a custom color for the text use that | |
if ( get_header_textcolor() != HEADER_TEXTCOLOR ) : | |
?> | |
#site-title a, | |
#site-description { | |
color: #<?php echo get_header_textcolor(); ?>; | |
} | |
<?php endif; ?> | |
#headimg img { | |
max-width: 1000px; | |
height: auto; | |
width: 100%; | |
} | |
</style> | |
<?php | |
} | |
endif; // twentyeleven_admin_header_style | |
if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : | |
/** | |
* Custom header image markup displayed on the Appearance > Header admin panel. | |
* | |
* Referenced via add_custom_image_header() in twentyeleven_setup(). | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_admin_header_image() { ?> | |
<div id="headimg"> | |
<?php | |
if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ) | |
$style = ' style="display:none;"'; | |
else | |
$style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"'; | |
?> | |
<h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1> | |
<div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> | |
<?php $header_image = get_header_image(); | |
if ( ! empty( $header_image ) ) : ?> | |
<img src="<?php echo esc_url( $header_image ); ?>" alt="" /> | |
<?php endif; ?> | |
</div> | |
<?php } | |
endif; // twentyeleven_admin_header_image | |
/** | |
* Sets the post excerpt length to 40 words. | |
* | |
* To override this length in a child theme, remove the filter and add your own | |
* function tied to the excerpt_length filter hook. | |
*/ | |
function twentyeleven_excerpt_length( $length ) { | |
return 40; | |
} | |
add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); | |
/** | |
* Returns a "Continue Reading" link for excerpts | |
*/ | |
function twentyeleven_continue_reading_link() { | |
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>'; | |
} | |
/** | |
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and twentyeleven_continue_reading_link(). | |
* | |
* To override this in a child theme, remove the filter and add your own | |
* function tied to the excerpt_more filter hook. | |
*/ | |
function twentyeleven_auto_excerpt_more( $more ) { | |
return ' …' . twentyeleven_continue_reading_link(); | |
} | |
add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); | |
/** | |
* Adds a pretty "Continue Reading" link to custom post excerpts. | |
* | |
* To override this link in a child theme, remove the filter and add your own | |
* function tied to the get_the_excerpt filter hook. | |
*/ | |
function twentyeleven_custom_excerpt_more( $output ) { | |
if ( has_excerpt() && ! is_attachment() ) { | |
$output .= twentyeleven_continue_reading_link(); | |
} | |
return $output; | |
} | |
add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); | |
/** | |
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. | |
*/ | |
function twentyeleven_page_menu_args( $args ) { | |
$args['show_home'] = true; | |
return $args; | |
} | |
add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); | |
/** | |
* Register our sidebars and widgetized areas. Also register the default Epherma widget. | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_widgets_init() { | |
register_widget( 'Twenty_Eleven_Ephemera_Widget' ); | |
register_sidebar( array( | |
'name' => __( 'Main Sidebar', 'twentyeleven' ), | |
'id' => 'sidebar-1', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => "</aside>", | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>', | |
) ); | |
register_sidebar( array( | |
'name' => __( 'Showcase Sidebar', 'twentyeleven' ), | |
'id' => 'sidebar-2', | |
'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => "</aside>", | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>', | |
) ); | |
register_sidebar( array( | |
'name' => __( 'Footer Area One', 'twentyeleven' ), | |
'id' => 'sidebar-3', | |
'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => "</aside>", | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>', | |
) ); | |
register_sidebar( array( | |
'name' => __( 'Footer Area Two', 'twentyeleven' ), | |
'id' => 'sidebar-4', | |
'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => "</aside>", | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>', | |
) ); | |
register_sidebar( array( | |
'name' => __( 'Footer Area Three', 'twentyeleven' ), | |
'id' => 'sidebar-5', | |
'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => "</aside>", | |
'before_title' => '<h3 class="widget-title">', | |
'after_title' => '</h3>', | |
) ); | |
} | |
add_action( 'widgets_init', 'twentyeleven_widgets_init' ); | |
if ( ! function_exists( 'twentyeleven_content_nav' ) ) : | |
/** | |
* Display navigation to next/previous pages when applicable | |
*/ | |
function twentyeleven_content_nav( $nav_id ) { | |
global $wp_query; | |
if ( $wp_query->max_num_pages > 1 ) : ?> | |
<nav id="<?php echo $nav_id; ?>"> | |
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3> | |
<div class="nav-previous" style="display:none;"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div> | |
<div class="nav-next" style="display:none;"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div> | |
</nav><!-- #nav-above --> | |
<?php endif; | |
} | |
endif; // twentyeleven_content_nav | |
/** | |
* Custom Menu Integration | |
*/ | |
/* | |
add_action('init', 'register_custom_menu'); | |
function register_custom_menu() { | |
register_nav_menu('custom_menu', __('Custom Menu')); | |
} | |
*/ | |
add_theme_support( 'menus' ); | |
/** | |
* Return the URL for the first link found in the post content. | |
* | |
* @since Twenty Eleven 1.0 | |
* @return string|bool URL or false when no link is present. | |
*/ | |
function twentyeleven_url_grabber() { | |
if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) | |
return false; | |
return esc_url_raw( $matches[1] ); | |
} | |
/** | |
* Count the number of footer sidebars to enable dynamic classes for the footer | |
*/ | |
function twentyeleven_footer_sidebar_class() { | |
$count = 0; | |
if ( is_active_sidebar( 'sidebar-3' ) ) | |
$count++; | |
if ( is_active_sidebar( 'sidebar-4' ) ) | |
$count++; | |
if ( is_active_sidebar( 'sidebar-5' ) ) | |
$count++; | |
$class = ''; | |
switch ( $count ) { | |
case '1': | |
$class = 'one'; | |
break; | |
case '2': | |
$class = 'two'; | |
break; | |
case '3': | |
$class = 'three'; | |
break; | |
} | |
if ( $class ) | |
echo 'class="' . $class . '"'; | |
} | |
if ( ! function_exists( 'twentyeleven_comment' ) ) : | |
/** | |
* Template for comments and pingbacks. | |
* | |
* To override this walker in a child theme without modifying the comments template | |
* simply create your own twentyeleven_comment(), and that function will be used instead. | |
* | |
* Used as a callback by wp_list_comments() for displaying the comments. | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_comment( $comment, $args, $depth ) { | |
$GLOBALS['comment'] = $comment; | |
switch ( $comment->comment_type ) : | |
case 'pingback' : | |
case 'trackback' : | |
?> | |
<li class="post pingback"> | |
<p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p> | |
<?php | |
break; | |
default : | |
?> | |
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> | |
<article id="comment-<?php comment_ID(); ?>" class="comment"> | |
<footer class="comment-meta"> | |
<div class="comment-author vcard"> | |
<?php | |
$avatar_size = 68; | |
if ( '0' != $comment->comment_parent ) | |
$avatar_size = 39; | |
echo get_avatar( $comment, $avatar_size ); | |
/* translators: 1: comment author, 2: date and time */ | |
printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ), | |
sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), | |
sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>', | |
esc_url( get_comment_link( $comment->comment_ID ) ), | |
get_comment_time( 'c' ), | |
/* translators: 1: date, 2: time */ | |
sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() ) | |
) | |
); | |
?> | |
<?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?> | |
</div><!-- .comment-author .vcard --> | |
<?php if ( $comment->comment_approved == '0' ) : ?> | |
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em> | |
<br /> | |
<?php endif; ?> | |
</footer> | |
<div class="comment-content"><?php comment_text(); ?></div> | |
<div class="reply"> | |
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>↓</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> | |
</div><!-- .reply --> | |
</article><!-- #comment-## --> | |
<?php | |
break; | |
endswitch; | |
} | |
endif; // ends check for twentyeleven_comment() | |
/* FUNCTION FOR TIME/DATE WITHIN AND AFTER 24 HOURS */ | |
add_filter('the_time', 'timeago'); | |
function timeago() | |
{ | |
global $post; | |
$date = $post->post_date; | |
$time = get_post_time('G', true, $post); | |
$time_diff = time() - $time; | |
if( $time_diff > 0 && $time_diff < 24*60*60 ) | |
$display = sprintf( __('%s ago'), human_time_diff( $time ) ); | |
else | |
$display = date(get_option('date_format'), strtotime($date) ); | |
return $display; | |
} | |
if ( ! function_exists( 'twentyeleven_posted_on' ) ) : | |
/** | |
* Prints HTML with meta information for the current post-date/time and author. | |
* Create your own twentyeleven_posted_on to override in a child theme | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_posted_on() { | |
printf( __( '<time class="entry-date" datetime="%3$s" pubdate>%4$s</time>', 'twentyeleven' ), | |
esc_url( get_permalink() ), | |
esc_attr( get_the_time() ), | |
esc_attr( get_the_date( 'c' ) ), | |
esc_html( get_the_date() ), | |
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), | |
esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), | |
get_the_author() | |
); | |
} | |
endif; | |
/** | |
* Adds two classes to the array of body classes. | |
* The first is if the site has only had one author with published posts. | |
* The second is if a singular post being displayed | |
* | |
* @since Twenty Eleven 1.0 | |
*/ | |
function twentyeleven_body_classes( $classes ) { | |
if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) | |
$classes[] = 'single-author'; | |
if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) | |
$classes[] = 'singular'; | |
return $classes; | |
} | |
add_filter( 'body_class', 'twentyeleven_body_classes' ); | |
// Adds descriptive text to link titles | |
// With help from http://blog.clearskys.net/2008/12/17/how-to-adding-menu-sub-titles-to-a-theme/ | |
function sub_page_list() { | |
global $wpdb; | |
$sql = "select p.id, p.post_title, p.guid, pd.meta_value "; | |
$sql .= "from " . $wpdb->posts . " p, " . $wpdb->postmeta . " pd, "; | |
$sql .= $wpdb->posts . " np, " . $wpdb->postmeta . " npd "; | |
$sql .= "where np.post_type = 'nav_menu_item' and np.post_status = 'publish' "; | |
$sql .= "and np.id = npd.post_id and npd.meta_key = '_menu_item_object_id' "; | |
$sql .= "and p.id = npd.meta_value and p.id = pd.post_id and pd.meta_key = "; | |
$sql .= "'thumbnail_image' order by np.menu_order asc limit 6"; | |
$rows = $wpdb->get_results($sql,OBJECT); | |
if($rows) { | |
$counter = 1; | |
foreach($rows as $row) { | |
echo "<div class=\"container padding-left-1 padding-right-23"; | |
if ($counter < count($rows)) | |
echo " margin-right-7 border-right\">"; | |
else | |
echo "\">"; | |
$counter++; | |
echo "<div>"; | |
$link_url = get_permalink($row->id); | |
echo "<a href=\"$link_url\"" . "\">"; | |
echo "<img height=\"100\" border=\"0\" width=\"145\" src=\"" . $row->meta_value . "\" class=\"\" style=\"display: inline;/\"></a>"; | |
echo "</div>"; | |
echo "<div><p class=\"clear-right heading heading3\">"; | |
echo "<a href=\"$link_url\"" . "\">" . get_post_meta($post->ID, 'Web Headline', $single = true) . "</a>"; | |
echo "</p></div>"; | |
echo "</div>"; | |
} | |
} | |
} | |
// Filter the menu to add the list | |
function childtheme_page_menu() { ?> | |
<div style="margin-bottom:15px; height:145px; width:980px;" class="module carousel-blog img-border padding-top shading gray5 padding-left padding-top no-padding-bottom " id="carousel-blog"> | |
<?php sub_page_list(); ?> | |
</div> | |
<?php } | |
function display_first_post_tag_link() | |
{ | |
$posttags = get_the_tags(); | |
$count = 0; | |
if ( count($posttags) > 1 ) { | |
foreach ($posttags as $tag) { | |
$count++; | |
if($count == 1) continue; | |
printf( | |
'<div class="tags-link"><a href="%1$s" itemprop="url"><span itemprop="title">%2$s</span></a></div>', | |
get_tag_link( $tag->term_id ), | |
esc_html( $tag->name ) | |
); | |
break; | |
} | |
} else { | |
print ('<div class="no-tags" style="padding-top:28px;"></div>'); | |
} | |
} | |
function get_first_tag_for_header() | |
{ | |
if ( $posttags = get_the_tags() ) { | |
$tag = current( $posttags ); | |
printf( | |
'<a href="%1$s">%2$s</a>', | |
get_tag_link( $tag->term_id ), | |
esc_html( $tag->name ) | |
); | |
} else { | |
print (''); | |
} | |
} | |
//automatically create bit.ly url for wordpress widgets | |
function bitly() | |
{ | |
//login information | |
$url = get_permalink(); //for wordpress permalink | |
$login = 'wpost'; //your bit.ly login | |
$apikey = 'R_2dd4d1d7af2bdd1a9c23af14cb68ee6a'; //add your bit.ly API | |
$format = 'json'; //choose between json or xml | |
$version = '2.0.1'; | |
//generate the URL | |
$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$apikey.'&format='.$format; | |
//fetch url | |
$response = file_get_contents($bitly); | |
//for json formating | |
if(strtolower($format) == 'json') | |
{ | |
$json = @json_decode($response,true); | |
echo $json['results'][$url]['shortUrl']; | |
} | |
else //for xml formatting | |
{ | |
$xml = simplexml_load_string($response); | |
echo 'http://bit.ly/'.$xml->results->nodeKeyVal->hash; | |
} | |
} | |
add_filter('wp_page_menu','childtheme_page_menu'); | |
/* Function to Remove Automatic Placement of Print Button From Printme plugin */ | |
remove_filter( 'the_content', 'printme_add_link' ); | |
//add_action('save_post', 'process_image_sizes'); | |
function process_image_sizes($post_id) { | |
$images = get_post_meta($post_id, 'image', false); | |
for ($i = 0; $i < count($images); $i=$i+1) { | |
$updated_meta_content = ""; | |
$size = array(); | |
$image_parts_array = str_getcsv($images[$i], '|'); | |
if (count($image_parts_array) == 3) { | |
$size = getimagesize($image_parts_array[0]); | |
$updated_meta_content = $images[$i] . "|" . $size[0] . "|" . $size[1]; | |
delete_post_meta($post_id, 'image', $images[$i]); | |
add_post_meta($post_id, 'image', $updated_meta_content); | |
} | |
} | |
} | |
/* | |
* | |
* | |
* IMAGE META BOXES | |
* | |
* | |
*/ | |
add_action('admin_menu', 'create_meta_box'); | |
add_action('save_post', 'save_postdata'); | |
$new_meta_boxes = | |
array( | |
"image_src" => array( | |
"name" => "image_src", | |
"std" => "", | |
"title" => "Image URL", | |
"description" => "Copy and Paste the image URL here."), | |
"caption" => array( | |
"name" => "caption", | |
"std" => "", | |
"title" => "Caption", | |
"description" => "Insert a caption of the photograph."), | |
"credit" => array( | |
"name" => "credit", | |
"std" => "", | |
"title" => "Credit", | |
"description" => "Give credit to the artist.") | |
); | |
function create_image_meta_box_html(){ | |
global $post, $new_meta_boxes; | |
$subhead = get_post_meta($post->ID, 'subhead', true); | |
echo '<script type ="text/javascript"> | |
var i=0; | |
for(e=0; e<=6; e++){ | |
var row ="<tr> <td> <input type=\"text\" name=\"img_src"+i+"\" value=\"\"/></td><td> <input type=\"text\" name=\"caption"+i+"value=\"\" /> </td><td> <input type=\"text\" name=\"credit"+i+"value=\"+i\" /><td></tr>"; | |
document.getElementById("OURCUSTOMTABLE").innerHTML += row; | |
i=i+1 | |
} | |
function addRow(){ | |
var e=0; | |
for(e=0; e<=4; e++){ | |
var row ="<tr> <td> <input type=\"text\" name=\"img_src"+i+"\" value=\"\"/></td><td> <input type=\"text\" name=\"caption"+i+"value=\"\" /> </td><td> <input type=\"text\" name=\"credit"+i+"value=\"+i\" /><td></tr>"; | |
document.getElementById("OURCUSTOMTABLE").innerHTML +=row; | |
i=i+1; | |
var elem = document.getElementById("boxes_count").value++;}} | |
</script>'; | |
echo '<table id="OURCUSTOMTABLE" border="0">'; | |
echo '<tr><th>Subhead</th></tr>'; | |
echo '<tr><td> <input type="text" name="Subhead" value="'.$subhead.'" /></td></tr>'; | |
echo ' | |
<tr> | |
<th>Image URL</th> | |
<th>Caption</th> | |
<th>Credit</th> | |
</tr> | |
<tr> '; | |
$combined_images = get_post_meta($post->ID, "image"); | |
$parsed_images_array = array(); | |
foreach ($combined_images as $combined_image) { | |
$parsed_image_array = str_getcsv($combined_image, '|'); | |
array_push($parsed_images_array, $parsed_image_array); | |
} | |
if (isset($combined_images)) { | |
for ($i=0; $i < count($combined_images); $i++) { | |
echo '<tr>'; | |
echo '<td> <input type="text" name="img_src'.$i.'" value="'.$parsed_images_array[$i]['0'].'" /> </td>'; | |
echo '<td> <input type="text" name="caption'.$i.'" value="'.$parsed_images_array[$i]['1'].'" /> </td>'; | |
echo '<td> <input type="text" name="credit'.$i.'" value="'.$parsed_images_array[$i]['2'].'" /> </td>'; | |
echo '</tr>'; | |
} | |
$extra_row_limit = count($combined_images) + 7; | |
for ($i = count($combined_images);$i < $extra_row_limit; $i++) { | |
echo '<tr>'; | |
echo '<td> <input type="text" name="img_src'.$i.'" value="" /> </td>'; | |
echo '<td> <input type="text" name="credit'.$i.'" value="" /> </td>'; | |
echo '<td> <input type="text" name="caption'.$i.'" value="" /> </td>'; | |
echo '</tr>'; | |
} | |
echo '<input type="hidden" name="boxes_count" value="'.$extra_row_limit.'"" />'; | |
} else { | |
$num_of_blank_boxes_by_default = 7; | |
for ($i = 0;$i < $num_of_blank_boxes_by_default; $i++) { | |
echo '<tr>'; | |
echo '<td> <input type="text" name="img_src'.$i.'" value="" /> </td>'; | |
echo '<td> <input type="text" name="caption'.$i.'" value="" /> </td>'; | |
echo '<td> <input type="text" name="credit'.$i.'" value="" /> </td>'; | |
echo '</tr>'; | |
} | |
echo '<input type="hidden" id="boxes_count" value=7'.$num_of_blank_boxes_by_default.'" />'; | |
} | |
echo '</table>'; | |
echo '<button type = "button" onclick="addRow()">Add More Rows</button>'; | |
} | |
function create_meta_box() { | |
add_meta_box( 'new-meta-boxes', 'Gallery Settings', 'create_image_meta_box_html', 'post', 'normal', 'high' ); | |
} | |
function save_postdata( $post_id ) { | |
$max_width = 800; | |
$max_height = 600; | |
delete_post_meta($post_id, 'image'); | |
$boxes_count = $_POST['boxes_count']; | |
for ($i = 0; $i < $boxes_count; $i++) { | |
$img_src = $_POST['img_src'.$i]; | |
$caption = $_POST['caption'.$i]; | |
$credit = $_POST['credit'.$i]; | |
if($img_src!='') { | |
$size = array(); | |
$size = getimagesize($img_src); | |
$w = 0; $h = 0; $w_scale = 0; $h_scale = 0; | |
$marg = array('top'=>'0px', 'right'=>'0px', 'bottom'=>'0px', 'left'=>'0px'); | |
$w = $size[0]; | |
$h = $size[1]; | |
$del_w = abs($max_width-$w); | |
$del_h = abs($max_height-$h); | |
if (($w > $max_width) && ($h > $max_height)) { | |
// Oversized Images | |
if ($del_w > $del_h) { | |
// Scale by Width | |
$w_scale = $max_width; | |
$h_scale = ($h * ($max_width/$w)); | |
$marg['top'] = intval((($max_height - $h_scale))/2).'px'; | |
} | |
else { | |
// Scale by Height | |
$h_scale = $max_height; | |
$w_scale = ($w * ($max_height/$h)); | |
$marg['left'] = intval((($max_width - $w_scale))/2).'px'; | |
} | |
} | |
else if (($w>$max_width) && ($h<=$max_height)) { | |
// Panoramic Images | |
$w_scale = $max_width; | |
$h_scale = ($h * ($max_width/$w)); | |
$marg['top'] = intval((($max_height - $h_scale))/2).'px'; | |
} | |
else if (($w<=$max_width) && ($h>$max_height)) { | |
// Long Images | |
$h_scale = $max_height; | |
$w_scale = ($w * ($max_height/$h)); | |
$marg['left'] = intval((($max_width - $w_scale))/2).'px'; | |
} | |
else { | |
// Undersized Images | |
$w_scale = $w; $h_scale = $h; | |
$marg['top'] = ($del_h/2).'px'; $marg['left'] = ($del_w/2).'px'; | |
} | |
$marg['top'].=' ';$marg['right'].=' ';$marg['bottom'].=' '; | |
$output = array($img_src, $caption, $credit, $w, $h, intval($w_scale), intval($h_scale), $marg['top'], $marg['right'], $marg['bottom'], $marg['left']); | |
$updated_meta_content = implode("|",$output); | |
add_post_meta($post_id, 'image', $updated_meta_content, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment