<?php /** * Carlton Gate functions and definitions * * @package WordPress * @subpackage Carlton_Gate * @since Carlton Gate 1.0 */ require_once get_template_directory() . '/functions/pixelwood.php'; require_once get_template_directory() . '/functions/comments.php'; require_once get_template_directory() . '/functions/theme-options.php'; require_once get_template_directory() . '/functions/ajax-forms.php'; require_once get_template_directory() . '/functions/page.php'; require_once get_template_directory() . '/functions/post.php'; # Custom Post Types require_once get_template_directory() . '/functions/property.php'; function image_select_tool( $title, $field, $prefix, $thumbsize = 'admin-preview', $format = 'table' ){ global $post; $value = get_post_meta( $post->ID, '_'.$prefix.$field, true ); $button_text = "Select Image"; if( $format == 'div' ): ?> <div id="tr-<?php echo $prefix . $field; ?>" style="overflow: auto;"> <p><strong><?php echo $title; ?></strong></p> <input id="<?php echo $prefix . $field; ?>" type="hidden" name="<?php echo $prefix . $field; ?>" value="<?php echo $value; ?>" /> <div id="<?php echo $prefix . $field; ?>-preview" style="margin-bottom: 8px; float: left; margin-right: 20px;"> <?php if( !empty( $value )){ $button_text = "Change Image"; echo wp_get_attachment_image( $value, $thumbsize ); } ?> </div> <input id="<?php echo $prefix . $field; ?>-button" class="button" type="button" value="<?php echo $button_text; ?>" /> <div id="<?php echo $prefix . $field; ?>-message" style="padding-top: 15px; font-style: italic; font-size: 13px;"></div> </div> <?php else: ?> <tr id="tr-<?php echo $prefix . $field; ?>"> <th scope="row"><label><?php echo $title; ?></label></th> <td> <input id="<?php echo $prefix . $field; ?>" type="hidden" name="<?php echo $prefix . $field; ?>" value="<?php echo $value; ?>" /> <div id="<?php echo $prefix . $field; ?>-preview" style="margin-bottom: 8px; float: left; margin-right: 20px;"> <?php if( !empty( $value )){ $button_text = "Change Image"; echo wp_get_attachment_image( $value, $thumbsize ); } ?> </div> <input id="<?php echo $prefix . $field; ?>-button" class="button" type="button" value="<?php echo $button_text; ?>" /> <div id="<?php echo $prefix . $field; ?>-message" style="padding-top: 15px; font-style: italic; font-size: 13px;"></div> </td> </tr> <?php endif; } /* function my_handle_upload_prefilter ( $params ) { $filePath = $params['file']; if ( (!is_wp_error($params)) && file_exists($filePath) && in_array($params['type'], array('image/png','image/gif','image/jpeg'))) { $quality = 100; list($largeWidth, $largeHeight) = array( 1000, 1000 ); list($oldWidth, $oldHeight) = getimagesize( $filePath ); list($newWidth, $newHeight) = wp_constrain_dimensions( $oldWidth, $oldHeight, $largeWidth, $largeHeight ); $resizeImageResult = image_resize( $filePath, $newWidth, $newHeight, false, null, null, $quality); unlink( $filePath ); if ( !is_wp_error( $resizeImageResult ) ) { $newFilePath = $resizeImageResult; rename( $newFilePath, $filePath ); } else { $params = wp_handle_upload_error ( $filePath, $resizeImageResult->get_error_message() ); } } return $params; } add_filter( 'wp_handle_upload_prefilter', 'my_handle_upload_prefilter' ); */ if ( ! function_exists( 'carltongate_setup' ) ) : /** * Carlton Gate setup. * * Set 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. * * @since Carlton Gate 1.0 */ function carltongate_setup() { // This theme styles the visual editor to resemble the theme style. add_editor_style( array( 'css/editor-style.css' ) ); // Add RSS feed links to <head> for posts and comments. add_theme_support( 'automatic-feed-links' ); // Enable support for Post Thumbnails, and declare two sizes. #add_theme_support( 'post-thumbnails' ); #set_post_thumbnail_size( 339, 9999, true ); // This theme uses wp_nav_menu() in two locations. register_nav_menus( array( 'primary' => 'Primary Menu', 'sitemap' => 'Footer Sitemap Menu', ) ); function custom_excerpt_length( $length ) { return 12; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); function new_excerpt_more($more) { return ''; } add_filter('excerpt_more', 'new_excerpt_more'); add_image_size( 'admin-preview', 100, 100, false ); add_image_size( 'footer-bar', 209, 167, true ); add_image_size( 'property-thumb', 65, 43, true ); add_image_size( 'property-medium', 170, 170, true ); add_image_size( 'property-large', 339, 9999, false ); add_image_size( 'property-large-wide', 560, 9999, false ); add_image_size( 'property-list', 214, 144, true ); add_image_size( 'page-head', 678, 194, true ); add_image_size( 'bottom-block', 339, 170, true ); } endif; // carltongate_setup add_action( 'after_setup_theme', 'carltongate_setup' ); /** * Enqueue scripts and styles for the front end. * * @since Carlton Gate 1.0 */ function carltongate_scripts() { wp_enqueue_style( 'carltongate-style', get_stylesheet_uri() ); wp_enqueue_style( 'carltongate-style-base', get_template_directory_uri() . '/css/base.css'.'?unique='.uniqid() ); wp_enqueue_style( 'carltongate-style-editor', get_template_directory_uri() . '/css/editor-style.css' ); wp_enqueue_style( 'carltongate-style-lightbox', get_template_directory_uri() . '/css/lightbox.css' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-color', get_template_directory_uri() . '/js/jquery.color.min.js', array( 'jquery' ) ); wp_enqueue_script( 'carltongate-lightbox', get_template_directory_uri() . '/js/lightbox.min.js', array( 'jquery' ) ); wp_enqueue_script( 'carltongate-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ) ); } add_action( 'wp_enqueue_scripts', 'carltongate_scripts' ); function carltongate_admin_scripts() { wp_enqueue_script( 'carltongate-admin-script', get_template_directory_uri() . '/js/admin.js', array( 'jquery' ) ); } add_action( 'admin_enqueue_scripts', 'carltongate_admin_scripts' ); /** * Create a nicely formatted and more specific title element text for output * in head of document, based on current view. * * @since Carlton Gate 1.0 * * @global int $paged WordPress archive pagination page count. * @global int $page WordPress paginated post page count. * * @param string $title Default title text for current view. * @param string $sep Optional separator. * @return string The filtered title. */ function carltongate_wp_title( $title, $sep ) { global $paged, $page; if ( is_feed() ) { return $title; } // Add the site name. $title .= get_bloginfo( 'name', 'display' ); // Add the site description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) { $title = "$title $sep $site_description"; } // Add a page number if necessary. if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { $title = "$title $sep " . sprintf( __( 'Page %s', 'carltongate' ), max( $paged, $page ) ); } if( str_replace( '/', '', $_SERVER['REQUEST_URI'] ) == 'property-map' ): $title = "Property Map " . $sep . " " . get_bloginfo( 'name', 'display' ); endif; return $title; } add_filter( 'wp_title', 'carltongate_wp_title', 10, 2 ); add_filter( 'next_posts_link_attributes', 'posts_link_attributes' ); add_filter( 'previous_posts_link_attributes', 'posts_link_attributes' ); function posts_link_attributes() { return 'class="button white"'; } if ( ! function_exists( 'carltongate_content_nav' ) ) : /** * Displays navigation to next/previous pages when applicable. * * @since Carlton Gate 1.0 */ function carltongate_content_nav() { global $wp_query; if ( $wp_query->max_num_pages > 1 ) : ?> <div class="post-navigation"> <div class="nav-previous alignleft"><?php next_posts_link( 'PREVIOUS' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'NEXT' ); ?></div> <div class="clear"></div> </div><!-- #<?php echo $html_id; ?> .navigation --> <?php endif; } endif; if ( ! function_exists( 'carltongate_posted_on' ) ) : /** * Print HTML with meta information for the current post-date/time and author. * * @since Carlton Gate 1.0 */ function carltongate_posted_on() { if ( is_sticky() && is_home() && ! is_paged() ) { echo '<span class="featured-post">' . __( 'Sticky', 'twentyfourteen' ) . '</span>'; } // Set up and print post meta information. printf( '<span class="entry-date"><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', esc_url( get_permalink() ), esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), get_the_author() ); } endif; # Map page fix add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', 'map_is_bad_hierarchical_slug', 10, 4 ); function map_is_bad_hierarchical_slug( $is_bad_hierarchical_slug, $slug, $post_type, $post_parent ) { if ( !$post_parent && $slug == 'property-map' ) return true; return $is_bad_hierarchical_slug; } add_filter( 'wp_unique_post_slug_is_bad_flat_slug', 'map_is_bad_flat_slug', 10, 3 ); function map_is_bad_flat_slug( $is_bad_flat_slug, $slug, $post_type ) { if ( $slug == 'property-map' ) return true; return $is_bad_flat_slug; } function catch_map(){ if( str_replace( '/', '', $_SERVER['REQUEST_URI'] ) == 'property-map' ): load_template( dirname( __FILE__ ) . '/templates/template-map.php' ); die; endif; } add_action( 'template_redirect', 'catch_map' ); function cg_type_per_page( $query ) { if ( is_admin() || !$query->is_main_query() ) return; if ( is_tax( 'type' ) ) $query->set( 'posts_per_page', -1 ); } add_action( 'pre_get_posts', 'cg_type_per_page', 1 );