<?php
// Install theme options needed for awesomeness
if( $_REQUEST['activated'] == true ):
update_option('thumbnail_size_w','150');
update_option('thumbnail_size_h','150');
update_option('medium_size_w','500');
update_option('medium_size_h','375');
update_option('posts_per_page','28');
endif;
// add support for post thumbnails
add_theme_support('post-thumbnails');
add_image_size('medium_gallery',500,375,1);
// register our secondary menu
function register_menus(){
if ( function_exists( 'register_nav_menu' ) ) {
register_nav_menu( 'secondary-menu', 'Secondary Menu' );
}
}
add_action('init','register_menus');
// Adds a link to the author and other contributors
function childtheme_theme_link($themelink) {
return $themelink . ' & <a href="http://upthemes.com/themes/gallery/" title="Gallery Wordpress Theme" rel="designer">Gallery WordPress Theme</a> by <a href="http://upthemes.com">UpThemes</a>';
}
add_filter('thematic_theme_link', 'childtheme_theme_link');
// add old school menus if user is not on WP 3.0
function gallery_page_menu(){ ?>
<div id="page-menu" class="menu">
<ul id="page-nav" class="sf-menu">
<li class="rss"><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('RSS Feed'); ?></a></li>
<?php wp_list_pages('title_li='); ?>
</ul>
</div>
<?php
}
function gallery_category_menu(){ ?>
<div id="category-menu" class="menu">
<ul id="category-nav" class="sf-menu">
<li class="home"><a href="<?php bloginfo('url'); ?>"><?php _e('Home'); ?></a></li>
<?php wp_list_categories('title_li='); ?>
</ul>
</div>
<?php
}
// add gallery menus
function childtheme_override_access() {
?>
<div id="access">
<?php
if( function_exists('wp_nav_menu') ):
$secondary = array(
'theme_location' => 'secondary-menu',
'container_class' => 'menu',
'container_id' => 'page-menu',
'menu_class' => 'sf-menu',
'menu_id' => 'page-nav',
'fallback_cb' => 'gallery_page_menu'
);
wp_nav_menu( $secondary );
$primary = array(
'theme_location' => 'primary-menu',
'container_class' => 'menu',
'container_id' => 'category-menu',
'menu_class' => 'sf-menu',
'menu_id' => 'category-nav',
'fallback_cb' => 'gallery_category_menu'
);
wp_nav_menu( $primary );
else:
gallery_page_menu();
gallery_category_menu();
endif;
?>
</div><!-- #access -->
<?php
}
add_action('thematic_access','gallery_menus',1);
// add UpThemes logo to blog title area in header
function childtheme_override_blogtitle(){
global $up_options;
echo '<div id="blog-title"><span><a href="' . get_bloginfo('url') . '/" title="' . get_bloginfo('name') . '" rel="home"><img src="' . $up_options->logo . '" alt="" /></a></span></div>';
}
add_action('thematic_header','childtheme_override_blogtitle',3);
// remove blog description from header
function childtheme_override_blogdescription(){
}
// remove sidebar on gallery-style pages
function remove_sidebar() {
if(is_page()){
return TRUE;
} else {
return FALSE;
}
}
add_filter('thematic_sidebar', 'remove_sidebar');
// add post thumbnail to RSS feed
function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = get_the_post_thumbnail($post->ID,'medium') . "<br/>" . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');
// remove navigation above & below
function remove_navigation() {
if( is_single() ):
remove_action('thematic_navigation_above', 'thematic_nav_above', 2);
remove_action('thematic_navigation_below', 'thematic_nav_below', 2);
endif;
}
add_action('wp_head', 'remove_navigation');
//
function sticky_footer(){
echo '<div class="push"></div></div><div class="footer">';
}
add_action('thematic_abovefooter','sticky_footer',100);
// add custom WP 3.0 menus
function gallery_navigation() {
global $post;
if ( !is_single() ) : ?>
<div id="nav-below" class="navigation">
<?php if(function_exists('wp_pagenavi')):
wp_pagenavi();
else : ?>
<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">«</span> Older posts', 'thematic')) ?></div>
<div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">»</span>', 'thematic')) ?></div>
<?php endif; ?>
</div>
<?php else: ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_post_link('%link', '<span class="meta-nav">«</span> %title') ?></div>
<div class="nav-next"><?php next_post_link('%link', '%title <span class="meta-nav">»</span>') ?></div>
</div>
<?php
endif;
}
add_action('gallery_navigation_below', 'gallery_navigation');
// create single post content
function remove_single_post() {
remove_action('thematic_singlepost', 'thematic_single_post');
}
add_action('init', 'remove_single_post');
// override the single post
function gallery_single_post() {
global $post;
if( function_exists('p75GetVideo') ):
if( p75GetVideo($post->ID) ):
$postclass = "video";
else:
$postclass = "gallery";
endif;
endif;
?>
<div id="post-<?php the_ID(); ?>" <?php post_class($postclass); ?>>
<div class="entry-content">
<?php if(function_exists('the_ratings')) { echo the_ratings(); } ?>
<h1><?php the_title(); ?></h1>
<?php the_content( __('Read More <span class="meta-nav">»</span>', 'thematic') ); ?>
<?php do_action('gallery_navigation_below'); ?>
</div><!-- /.entry-content -->
</div><!-- /.post -->
<div class="artwork-container">
<div class="entry-artwork">
<?php do_action('entry_artwork'); ?>
</div><!-- /.entry-artwork -->
</div><!-- /.artwork-container -->
<?php
}
add_action('thematic_singlepost', 'gallery_single_post');
// decide what to show in the single post image area
function what_to_show(){
global $post;
if( function_exists( 'p75GetVideo' ) ):
if( p75HasVideo( $post->ID ) ):
echo p75GetVideo($post->ID);
else:
show_medium_image();
endif;
else:
show_medium_image();
endif;
}
function show_medium_image(){
global $post;
$url = get_post_meta($post->ID, 'web-url', true);
$custom_image = get_post_meta($post->ID, 'full-image', true);
if( $url )
echo '<a href="' . get_post_meta($post->ID, 'web-url', true) . '">';
if( $custom_image ):
echo '<img src="' . $custom_image . '" alt="' . the_title_attribute('echo=0') . '"/>';
elseif( has_post_thumbnail() ):
the_post_thumbnail('medium_gallery');
else:
echo '<img src="' . get_bloginfo('stylesheet_directory') . '/images/full-image-default.jpg" alt="' . the_title_attribute('echo=0') . '"/>';
endif;
if( $url )
echo '</a>';
}
add_action('entry_artwork','what_to_show');
// decide what to add to single post
function setup_singlepost(){
if( is_single() )
add_filter('the_content','add_metadata_to_post',10);
}
add_action('wp_head','setup_singlepost');
// add meta data to the post
function add_metadata_to_post( $content ){
$content .= '<ul class="meta">';
$content .= add_twitter_to_meta();
$content .= add_designer_to_meta();
$content .= add_weburl_to_meta();
$content .= '</ul>';
return $content;
}
// add twitter to our meta data
function add_twitter_to_meta(){
global $up_options,$post;
if( function_exists('file_get_contents') )
$shortenedurl = file_get_contents( 'http://tinyurl.com/api-create.php?url=' . urlencode( get_permalink() ) );
else
$shortenedurl = urlencode( get_permalink() );
if( $up_options->twitter )
return '<li class="twitter"><a href="http://www.twitter.com/home?status=' . str_replace(' ', '+', the_title_attribute('echo=0')) . '+' . $shortenedurl . '+(via+@'. $up_options->twitter .')" title="Share ' . the_title_attribute('echo=0') . ' on Twitter">' . _('Tweet This') . '</a></li>';
}
// add the designer to the meta data
function add_designer_to_meta(){
global $post;
if( get_post_meta($post->ID, 'designed-by') )
return '<li class="designer">Designed by: ' . get_post_meta($post->ID, 'designed-by', $single = true) . '</li>';
}
// add the web URL to the meta data
function add_weburl_to_meta(){
global $post;
if( get_post_meta($post->ID, 'web-url') )
return '<li class="site-link"><a rel="source" href="' . get_post_meta($post->ID, 'web-url', $single = true) .'">' . get_post_meta($post->ID, 'web-url', $single = true) . '</a></li><li class="delicious"><a href="http://del.icio.us/post?url=' . get_post_meta($post->ID, 'web-url', $single = true) . '&' . get_the_title() . '">Bookmark This (' . get_post_meta($post->ID, 'web-url', $single = true) . ')</a></li>';
}
// remove all loops and replace them with our thumbnail loop
function remove_loops() {
remove_action('thematic_categoryloop', 'thematic_category_loop');
remove_action('thematic_tagloop', 'thematic_tag_loop');
remove_action('thematic_archiveloop', 'thematic_archive_loop');
remove_action('thematic_indexloop', 'thematic_index_loop');
}
add_action('init', 'remove_loops');
// add our thumbnail loop instead
function thumbnail_loop() {
global $post;
get_template_part( 'loop', 'thumbnail' );
}
add_action('thematic_categoryloop', 'thumbnail_loop');
add_action('thematic_tagloop', 'thumbnail_loop');
add_action('thematic_archiveloop', 'thumbnail_loop');
add_action('thematic_indexloop', 'thumbnail_loop');
// filter the page title
function gallery_page_title ($content) {
if (is_category()) {
$content = '<h1 class="page-title"><span>';
$content .= single_cat_title("", false);
$content .= '</span></h1>';
if ( !(''== category_description()) ) {
$content .= '<div class="archive-meta">';
$content .= apply_filters('archive_meta', category_description());
$content .= '</div>';
}
} elseif (is_tag()) {
$content = '<h1 class="page-title"><span>';
$content = thematic_tag_query();
$content = '</span></h1>';
}
return $content;
}
add_filter('thematic_page_title', 'gallery_page_title');
// add fix for ie6 styles
function fix_ie6(){
echo ' <!--[if lt IE 7]>
<script src="/wp-content/themes/gallery/js/DD_belatedPNG.js"></script>
<script type="text/javascript">
DD_belatedPNG.fix("body,#wrapper, ul.meta li,#blog-title a,#access,#access a,.new,#comments h3,ul.children li,.cover-up,.entry-content .post-ratings img,.post-ratings-image");
</script>
<![endif]-->';
}
add_action('wp_head','fix_ie6');
// add slider and lazyload
function gallery_slider(){
wp_enqueue_script( 'lazyload', get_bloginfo('stylesheet_directory') . '/js/jquery.lazyload.pack.js', array('jquery') );
wp_enqueue_script( 'gallery', get_bloginfo('stylesheet_directory') . '/js/gallery.js', array('jquery','lazyload') );
}
add_action('init','gallery_slider');
// add custom post header
function childtheme_post_header(){
global $up_options;
$gall_newlength = $up_options->new_length;
if($gall_newlength){
$time = $gall_newlength;
} else {
$time = 3;
}
if ( (time()-get_the_time('U')) <= ($time*86400) ):
echo '<div class="new"></div>';
endif;
}
// add category nicenames in body and post class
function not_singular_body_class($classes) {
global $post,$wpdb,$wp_query;
if( is_home() || is_category() || is_archive() || is_tag() ):
$classes[] = 'not-singular';
endif;
return $classes;
}
add_filter('body_class', 'not_singular_body_class');
/*
Plugin Name: Custom Write Panel
Plugin URI: http://wefunction.com/2008/10/tutorial-create-custom-write-panels-in-wordpress
Description: Allows custom fields to be added to the WordPress Post Page
Version: 1.0
Author: Spencer
Author URI: http://wefunction.com
/* ----------------------------------------------*/
$new_meta_boxes = array(
"full-image" => array(
"name" => "full-image",
"std" => "",
"title" => "Path to Full-Size Image (500x375)",
"description" => "Using the \"<em>Add an Image</em>\" button, upload a 500x375 image and paste the URL here."),
"thumbnail" => array(
"name" => "thumbnail",
"std" => "",
"title" => "Path to Thumbnail Image (125x125)",
"description" => "Using the \"<em>Add an Image</em>\" button, upload a 125x125 thumbnail image and paste the URL here."),
"designed-by" => array(
"name" => "designed-by",
"std" => "",
"title" => "Designed by",
"description" => "Enter the name of the designer (if known or applicable)."),
"web-url" => array(
"name" => "web-url",
"std" => "",
"title" => "Website URL",
"description" => "Enter the full website URL (if applicable).")
);
function new_meta_boxes() {
global $post, $new_meta_boxes;
foreach($new_meta_boxes as $meta_box) {
$meta_box_value = get_post_meta($post->ID, $meta_box['name'], true);
if($meta_box_value == "")
$meta_box_value = $meta_box['std'];
echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
echo'<label style="font-weight: bold; display: block; padding: 5px 0 2px 2px" for="'.$meta_box['name'].'">'.$meta_box['title'].'</label>';
echo'<input type="text" name="'.$meta_box['name'].'" value="'.$meta_box_value.'" size="55" /><br />';
echo'<p><label for="'.$meta_box['name'].'">'.$meta_box['description'].'</label></p>';
}
}
function create_meta_box() {
global $theme_name;
if ( function_exists('add_meta_box') ) {
add_meta_box( 'new-meta-boxes', 'Gallery Post Settings', 'new_meta_boxes', 'post', 'normal', 'high' );
}
}
function save_postdata( $post_id ) {
global $post, $new_meta_boxes;
foreach($new_meta_boxes as $meta_box) {
// Verify
if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
return $post_id;
}
if ( 'page' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ))
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ))
return $post_id;
}
$data = $_POST[$meta_box['name']];
if(get_post_meta($post_id, $meta_box['name']) == "")
add_post_meta($post_id, $meta_box['name'], $data, true);
elseif($data != get_post_meta($post_id, $meta_box['name'], true))
update_post_meta($post_id, $meta_box['name'], $data);
elseif($data == "")
delete_post_meta($post_id, $meta_box['name'], get_post_meta($post_id, $meta_box['name'], true));
}
}
add_action('admin_menu', 'create_meta_box');
add_action('save_post', 'save_postdata');
include_once('admin/functions.php');
?>