'; } else if ( $size == 'thumbnail' ) { $html = str_replace( 'class="', 'class="thumbnail ', $html ); } } if ( in_array( $size, array( 'post-thumbnail', 'franz-medium' ) ) ) { $html = str_replace( 'class="', 'class="img-responsive ', $html ); } return $html; } add_filter( 'post_thumbnail_html', 'franz_post_thumbnail_html', 10, 5 ); /** * Determine the correct template part to load */ function franz_get_template_part( $p1, $p2 = '' ){ if ( $p1 == 'loop' && ! $p2 ) { $p2 = get_post_format(); $filename = '/formats/loop-' . $p2 . '.php'; if ( $p2 != 'standard' && ( file_exists( FRANZ_ROOTDIR . $filename ) || file_exists( FJ_CHILDDIR . $filename ) ) ) $p1 = 'formats/loop'; else $p2 = ''; } get_template_part( $p1, $p2 ); } /** * Add custom classes to posts */ function franz_body_class( $classes ){ global $franz_settings; if ( is_singular() || is_author() ) $classes[] = 'singular'; else $classes[] = 'non-singular'; if ( ! is_singular() && ! is_author() && $franz_settings['tiled_posts'] ) $classes[] = 'tiled-posts'; if ( ! $franz_settings['disable_top_bar'] ) $classes[] = 'has-top-bar'; $classes[] = franz_column_mode(); return $classes; } add_filter( 'body_class', 'franz_body_class' ); /** * Determine the main content area class for layout */ function franz_main_content_classes( $classes = array() ) { $column_mode = franz_column_mode(); if ( stripos( $column_mode, 'left-sidebar' ) !== false ) $classes[] = 'col-md-push-3'; if ( stripos( $column_mode, 'one-column' ) !== false ) { $classes[] = 'col-md-12'; $classes = array_diff( $classes, array( 'col-md-9') ); } echo implode( ' ', $classes ); } /** * Entry meta */ function franz_entry_meta(){ global $franz_settings, $post; $post_id = get_the_ID(); $author_id = $post->post_author; $meta = array(); /* Don't get meta for pages */ if ( 'page' == get_post_type( $post_id ) ) return; /* Print button */ if ( $franz_settings['print_button'] && is_singular() ) { $meta['print'] = array( 'class' => 'print-button', 'meta' => '', ); } /* Post date */ $meta['date'] = array( 'class' => 'date', 'meta' => '' . get_the_time( get_option( 'date_format' ) ) . '', ); /* Post author and categories */ if ( ! $franz_settings['hide_post_cat'] ) { $cats = get_the_category(); $categories = array(); if ( $cats ) { foreach ( $cats as $cat ) $categories[] = '' . $cat->name . ''; } if ( $categories ) $categories = '' . implode( ', ', $categories ) . ''; } if ( ! $franz_settings['hide_post_author'] ) { $author = ''; } if ( $categories && $author ) $byline = sprintf( __( 'By %1$s under %2$s', 'franz-josef' ), $author, $categories ); elseif ( $categories ) $byline = sprintf( __( 'Filed under %2$s', 'franz-josef' ), $author, $categories ); elseif ( $author ) $byline = sprintf( __( 'By %s', 'franz-josef' ), $author ); else $byline = false; if ( $byline ) $meta['byline'] = array( 'class' => 'byline', 'meta' => $byline ); /* Comments link */ if ( franz_should_show_comments( $post_id ) ) { $comment_count = get_comment_count( $post_id ); $approved_comment_count = $comment_count['approved']; $comment_text = ( $comment_count['approved'] ) ? sprintf( _n( '%d comment', '%d comments', $approved_comment_count, 'franz-josef' ), $approved_comment_count ) : __( 'Leave a reply', 'franz-josef' ); $comments_link = ( $comment_count['approved'] ) ? get_comments_link() : str_replace( '#comments', '#respond', get_comments_link() ); $meta['comments'] = array( 'class' => 'comments-count', 'meta' => '' . $comment_text . '', ); } /* Post tags */ $tags = get_the_tags(); if ( $tags ) { $html = ''; if ( count( $tags ) > 1 ) $html .= ''; else $html .= ''; $tag_links = array(); foreach ( $tags as $tag ) $tag_links[] = '' . $tag->name . ''; $html .= implode( ', ', $tag_links ); if ( $html ) $meta['tags'] = array( 'class' => 'entry-tags', 'meta' => $html ); } $meta = apply_filters( 'franz_entry_meta', $meta, $post_id ); if ( ! $meta ) return; ?> 'date updated', 'meta' => '' . get_the_time( get_option( 'date_format' ) ) . '', ); $comment_count = get_comment_count( $post_id ); $comment_text = ( $comment_count['approved'] ) ? $comment_count['approved'] : __( 'Leave a reply', 'franz-josef' ); $comments_link = ( $comment_count['approved'] ) ? get_comments_link() : str_replace( '#comments', '#respond', get_comments_link() ); $meta['comments'] = array( 'class' => 'comments-count', 'meta' => ' ' . $comment_text . '', ); $meta = apply_filters( 'franz_author_entry_meta', $meta ); if ( ! $meta ) return; ?> '; $markup[] = ''; /* Author */ $markup[] = ''; $markup = apply_filters( 'franz_structured_data_markup', $markup ); if ( ! $markup ) return; echo implode( "\n", $markup ); } add_action( 'franz_do_entry_meta', 'franz_structured_data_markup' ); /** * Control the excerpt length */ function franz_modify_excerpt_length( $length ) { global $franz_excerpt_length; if ( $franz_excerpt_length ) return $franz_excerpt_length; else return $length; } add_filter( 'excerpt_length', 'franz_modify_excerpt_length' ); /** * Set the excerpt length */ function franz_set_excerpt_length( $length ){ if ( ! $length ) return; global $franz_excerpt_length; $franz_excerpt_length = $length; } /** * Reset the excerpt length */ function franz_reset_excerpt_length(){ global $franz_excerpt_length; unset( $franz_excerpt_length ); } if ( ! function_exists( 'franz_page_navigation' ) ) : /** * List subpages of current page */ function franz_page_navigation(){ $current = get_the_ID(); $ancestors = get_ancestors( $current, 'page' ); if ( $ancestors ) $parent = $ancestors[0]; else $parent = $current; $args = array( 'post_type' => array( 'page' ), 'posts_per_page' => -1, 'post_parent' => $parent, 'orderby' => 'title', 'order' => 'ASC' ); $children = new WP_Query( apply_filters( 'franz_page_navigation_args', $args ) ); if ( $children->have_posts() ) : ?>

max( 1, get_query_var( 'paged' ) ), 'total' => $wp_query->max_num_pages, 'base' => '', 'format' => '', 'add_fragment' => '', 'type' => 'post', 'prev_text' => '«', 'next_text' => '»' ) ); $args = wp_parse_args( $args, $defaults ); $paginate_args = array( 'current' => $args['current'], 'total' => $args['total'], 'prev_text' => $args['prev_text'], 'next_text' => $args['next_text'], 'type' => 'array', 'echo' => false, 'add_fragment' => $args['add_fragment'], ); if ( $args['base'] ) $paginate_args['base'] = $args['base']; if ( $args['format'] ) $paginate_args['format'] = $args['format']; if ( $args['type'] == 'comment' ) $links = paginate_comments_links( apply_filters( 'franz_comments_nav_args', $paginate_args ) ); else $links = paginate_links( apply_filters( 'franz_posts_nav_args', $paginate_args ) ); if ( $links ) : ?> max( 1, get_query_var('cpage') ), 'total' => get_comment_pages_count(), 'base' => add_query_arg( 'cpage', '%#%' ), 'format' => '', 'add_fragment' => '#comments', 'prev_text' => __( '« Prev', 'franz-josef' ), 'next_text' => __( 'Next »', 'franz-josef' ), 'type' => 'comment', ) ); $args = wp_parse_args( $args, $defaults ); franz_posts_nav( $args ); } endif; /** * Add pagination links in pages */ function franz_link_pages(){ $args = array( 'before' => '', 'link_before' => '', 'link_after' => '', 'next_or_number' => 'number', 'separator' => '
  • ', 'pagelink' => '%', 'echo' => 0 ); $pages_link = wp_link_pages( apply_filters( 'franz_link_pages_args', $args ) ); $pages_link = explode( '
  • ', $pages_link ); foreach ( $pages_link as $i => $link ) { if ( stripos( $link, '', $pages_link ); } /** * Override the output of the submit button on forms, useful for * adding custom classes or other attributes. * * @param string $button An HTML string of the default button * @param array $form An array of form data * @return string $button * * @filter gform_submit_button */ function franz_gform_submit_button( $button, $form ) { $button = sprintf( '', absint( $form['id'] ), esc_attr( $form['button']['text'] ) ); return $button; } add_filter( 'gform_submit_button', 'franz_gform_submit_button', 10, 2 ); /** * Allows post queries to sort the results by the order specified in the post__in parameter. * Just set the orderby parameter to post__in! * * Based on the Sort Query by Post In plugin by Jake Goldman (http://www.get10up.com) */ function franz_sort_query_by_post_in( $sortby, $thequery ) { global $wpdb; if ( ! empty( $thequery->query['post__in'] ) && isset( $thequery->query['orderby'] ) && $thequery->query['orderby'] == 'post__in' ) $sortby = "find_in_set(" . $wpdb->prefix . "posts.ID, '" . implode( ',', $thequery->query['post__in'] ) . "')"; return $sortby; } add_filter( 'posts_orderby', 'franz_sort_query_by_post_in', 9999, 2 ); if ( ! function_exists( 'franz_single_author_bio' ) ) : /** * Print out author's bio */ function franz_single_author_bio(){ global $franz_settings, $post; if ( ! is_singular() || ( $franz_settings['hide_author_bio'] && ! franz_has_custom_layout() ) ) return; ?>
    $franz_settings['adjacent_posts_same_term'], 'excluded_terms'=> '', 'taxonomy' => 'category' ); $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); $prev_post = apply_filters( 'franz_prev_post', get_previous_post( $in_same_term, $excluded_terms, $taxonomy ) ); $next_post = apply_filters( 'franz_next_post', get_next_post( $in_same_term, $excluded_terms, $taxonomy ) ); if ( ! $prev_post && ! $next_post ) return; ?>

    ', ']]>', $text); /* Remove unwanted JS code */ $text = preg_replace( '@]*?>.*?@si', '', $text); /* Strip HTML tags, but allow certain tags */ $text = strip_tags( $text, $franz_settings['excerpt_html_tags'] ); $excerpt_length = apply_filters( 'excerpt_length', 55 ); $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[...]' ); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count( $words) > $excerpt_length ) { array_pop( $words); $text = implode( ' ', $words); $text = $text . $excerpt_more; } else { $text = implode( ' ', $words); } } // Try to balance the HTML tags $text = force_balance_tags( $text ); return apply_filters( 'wp_trim_excerpt', $text, $raw_excerpt); } /** * Only use the custom excerpt trimming function if user decides to retain html tags. */ if ( $franz_settings['excerpt_html_tags'] ) { remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); add_filter( 'get_the_excerpt', 'franz_improved_excerpt' ); } /** * Remove additional padding from captioned images */ function franz_cleaner_caption( $output, $attr, $content ) { /* We're not worried abut captions in feeds, so just return the output here. */ if ( is_feed() ) return $output; /* Set up the default arguments. */ $defaults = array( 'id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '' ); /* Merge the defaults with user input. */ $attr = shortcode_atts( $defaults, $attr ); /* If the width is less than 1 or there is no caption, return the content wrapped between the [caption]< tags. */ if ( 1 > $attr['width'] || empty( $attr['caption'] ) ) return $content; /* Set up the attributes for the caption
    . */ $attributes = ( !empty( $attr['id'] ) ? ' id="' . esc_attr( $attr['id'] ) . '"' : '' ); $attributes .= ' class="wp-caption ' . esc_attr( $attr['align'] ) . '"'; $attributes .= ' style="width: ' . esc_attr( $attr['width'] ) . 'px"'; /* Open the caption
    . */ $output = ''; /* Allow shortcodes for the content the caption was created for. */ $output .= do_shortcode( $content ); /* Append the caption text. */ $output .= '

    ' . $attr['caption'] . '

    '; /* Close the caption
    . */ $output .= '
    '; /* Return the formatted, clean caption. */ return $output; } add_filter( 'img_caption_shortcode', 'franz_cleaner_caption', 10, 3 ); /** * Check if current post has custom page layout * * @return boolean */ function franz_has_custom_layout() { global $post; if ( ! function_exists( 'fjs_load_textdomain' ) ) return false; if ( empty( $post ) ) return false; if ( ! is_singular() ) return false; if ( get_post_meta( $post->ID, 'panels_data', true ) ) return true; else return false; } /** * Output the custom layout if the current post has one * * @return boolean */ function franz_do_custom_layout() { if ( franz_has_custom_layout() ) { the_content(); get_footer(); exit(); } } add_action( 'franz_before_content', 'franz_do_custom_layout', 1000 ); /** * Check if there is usable image in the post */ function franz_has_post_image( $post_id = '' ){ /* Get the post ID if not provided */ if ( ! $post_id ) $post_id = get_the_ID(); if ( has_post_thumbnail( $post_id ) ) return true; if ( get_attached_media( 'image', $post_id ) ) return true; if ( get_post_gallery( $post_id, false ) ) return true; return false; } /** * Get the best available post image based on requested size */ function franz_get_post_image( $size = 'thumbnail', $post_id = '' ){ /* Get the requested dimension */ $size = apply_filters( 'franz_post_image_size', $size, $post_id ); if ( ! is_array( $size ) ) { $dimension = franz_get_image_sizes( $size ); if ( $size ) { $width = $dimension['width']; $height = $dimension['height']; } } else { $width = $size[0]; $height = $size[1]; } /* Get the post ID if not provided */ if ( ! $post_id ) $post_id = get_the_ID(); /* Get and return the cached result if available */ $cached_images = get_post_meta( $post_id, '_franz_post_images', true ); if ( $cached_images ) { if ( array_key_exists( $width . 'x' . $height, $cached_images ) ) return $cached_images[$width . 'x' . $height]; } else { $cached_images = array(); } $images = array(); $image_ids = array(); /* Check if the post has a featured image */ if ( has_post_thumbnail( $post_id ) ) { $image_id = get_post_thumbnail_id( $post_id ); $image = wp_get_attachment_image_src( $image_id, $size ); if ( $image ) { $images[] = array( 'id' => $image_id, 'featured' => true, 'url' => $image[0], 'width' => $image[1], 'height' => $image[2], 'aspect_ratio' => $image[1] / $image[2] ); $image_ids[] = $image_id; } } /* Get other images uploaded to the post */ $media = get_attached_media( 'image', $post_id ); if ( $media ) { foreach ( $media as $image ) { $image_id = $image->ID; $image = wp_get_attachment_image_src( $image_id, $size ); if ( $image ) { $images[] = array( 'id' => $image_id, 'featured' => false, 'url' => $image[0], 'width' => $image[1], 'height' => $image[2], 'aspect_ratio' => $image[1] / $image[2] ); $image_ids[] = $image_id; } } } /* Get the images from galleries in the post */ $galleries = get_post_galleries( $post_id, false ); if ( $galleries ) { foreach ( $galleries as $gallery ) { $gallery_images = explode( ',', $gallery['ids'] ); foreach ( $gallery_images as $image_id ) { if ( in_array( $image_id, $image_ids ) ) continue; $image = wp_get_attachment_image_src( $image_id, $size ); if ( $image ) { $images[] = array( 'id' => $image_id, 'featured' => false, 'url' => $image[0], 'width' => $image[1], 'height' => $image[2], 'aspect_ratio' => $image[1] / $image[2] ); $image_ids[] = $image_id; } } } } /* Score the images for best match to the requested size */ $weight = array( 'dimension' => 1.5, 'aspect_ratio' => 1, 'featured_image'=> 1 ); $target_aspect = $width / $height; foreach ( $images as $key => $image ) { $score = 0.0; /* Aspect ratio */ if ( $image['aspect_ratio'] > $target_aspect ) $score += ( $target_aspect / $image['aspect_ratio'] ) * $weight['aspect_ratio']; else $score += ( $image['aspect_ratio'] / $target_aspect ) * $weight['aspect_ratio']; /* Dimension: ( width ratio + height ratio ) / 2 */ $dim_score = min( array( ( $image['width'] / $width ), 1 ) ) + min( array( ( $image['height'] / $height ), 1 ) ); $score += ( $dim_score / 2 ) * $weight['dimension']; /* Featured image */ if ( $image['featured'] ) $score += $weight['featured_image']; $images[$key]['score'] = $score; } /* Sort the images based on the score */ usort( $images, 'franz_sort_array_key_score' ); $images = apply_filters( 'franz_get_post_image', $images, $size, $post_id ); if ( $images ) { $cached_images = array_merge( $cached_images, array( $width . 'x' . $height => $images[0] ) ); update_post_meta( $post_id, '_franz_post_images', $cached_images ); return $images[0]; } else { $cached_images = array_merge( $cached_images, array( $width . 'x' . $height => false ) ); update_post_meta( $post_id, '_franz_post_images', $cached_images ); return false; } } /** * Clear the post image cache when post is updated */ function franz_clear_post_image_cache( $post_id ){ if ( wp_is_post_revision( $post_id ) ) return; delete_post_meta( $post_id, '_franz_post_images' ); } add_action( 'save_post', 'franz_clear_post_image_cache' ); /** * Display the post's image */ function franz_the_post_image( $size = 'post-thumbnail', $attr = '' ) { $post_id = get_the_ID(); $image = franz_get_post_image( $size, $post_id ); if ( $image ) { do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['id'], $size ); $html = wp_get_attachment_image( $image['id'], $size, false, $attr ); do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['id'], $size ); } else { $html = ''; } echo apply_filters( 'post_thumbnail_html', $html, $post_id, $image['id'], $size, $attr ); } if ( ! function_exists( 'franz_featured_image' ) ) : /** * Display the featured image in single post pages */ function franz_featured_image() { global $franz_settings; $has_featured_image = true; if ( $franz_settings['hide_featured_image'] ) $has_featured_image = false; if ( ! has_post_thumbnail() ) $has_featured_image = false; else { /* Check if featured image size is at least as wide as the content area width */ global $content_width; $featured_image_id = get_post_thumbnail_id(); $featured_image = wp_get_attachment_metadata( $featured_image_id ); if ( $featured_image['width'] < $content_width ) $has_featured_image = false; } if ( $has_featured_image ) : ?>