__( 'Header Menu', 'bornholm' ),
) );
}
add_action( 'init', 'bornholm_menus' );
/**
* Registers the sidebar
*/
function bornholm_sidebars() {
register_sidebar( array(
'name' => 'Sidebar',
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '
',
'after_widget' => '
',
'before_title' => ''
) );
register_sidebar( array(
'name' => __( 'Gallery Sidebar', 'bornholm' ),
'id' => 'sidebar-gallery',
'description' => __( 'This sidebar is shown on single gallery pages', 'bornholm' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area (top)', 'bornholm' ),
'id' => 'footer-widget-area-top',
'description' => __( 'This widget area is shown on the top of the footer', 'bornholm' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area (bottom)', 'bornholm' ),
'id' => 'footer-widget-area-bottom',
'description' => __( 'This widget area is shown on the bottom of the footer', 'bornholm' ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => ''
) );
}
add_action( 'init', 'bornholm_sidebars' );
/**
* Displays navigation for paginated posts
*
* @return string Formatted output in HTML.
*/
function bornholm_paginated_posts_navigation() {
wp_link_pages( array(
'before' => '',
'link_before' => '',
'link_after' => ' ',
) );
}
/**
* Displays more link with title of post in quotation marks
*
* @return string Formatted output in HTML
*/
function bornholm_more_link() {
$text = _x( 'Continue reading “%s”', 's = post title', 'bornholm' );
$more = sprintf( $text, get_the_title() );
the_content( $more );
}
/**
* Removes the page jump after clicking on a read more link
*
* @param $link
*
* @return mixed
*/
function bornholm_remove_more_link_scroll( $link ) {
$link = preg_replace( '|#more-[0-9]+|', '', $link );
return $link;
}
add_filter( 'the_content_more_link', 'bornholm_remove_more_link_scroll' );
/**
* Adds the scripts and styles to the header
*/
function bornholm_scripts_styles() {
/*
* Adds JavaScript to pages with the comment form to support
* sites with threaded comments (when in use).
*/
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_enqueue_script( 'bornholm-menu', get_template_directory_uri() . '/js/menu.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'bornholm-lightbox', get_template_directory_uri() . '/js/lightbox.js', array( 'jquery' ), false, true );
/*
* Loads our main stylesheet.
*/
wp_enqueue_style( 'bornholm-style', get_template_directory_uri() . '/css/bornholm.css', array(), null );
wp_enqueue_style( 'bornholm-fonts', 'http://fonts.googleapis.com/css?family=Roboto:300,300italic,500,500italic', array(), null );
}
add_action( 'wp_enqueue_scripts', 'bornholm_scripts_styles' );
/**
* Fetch image post objects for all gallery images in a post.
*
* @param $post_id
* @return array
*/
function bornholm_get_gallery_images( $post_id ) {
$post = get_post( $post_id );
// Den Beitrag gibt es nicht, oder er ist leer.
if ( ! $post || empty ( $post->post_content ) ) {
return array();
}
$galleries = get_post_galleries( $post, false );
if ( empty ( $galleries ) ) {
return array();
}
$ids = array();
foreach ( $galleries as $gallery ) {
if ( ! empty ( $gallery['ids'] ) ) {
$ids = array_merge( $ids, explode( ',', $gallery['ids'] ) );
}
}
$ids = array_unique( $ids );
if ( empty ( $ids ) ) {
$attachments = get_children( array(
'post_parent' => $post_id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order',
) );
if ( empty ( $attachments ) ) {
return array();
}
}
$images = get_posts(
array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'post__in',
'numberposts' => 999,
'include' => $ids
)
);
if ( ! $images && ! $attachments ) {
return array();
} elseif ( ! $images ) {
$images = $attachments;
}
return $images;
}
/**
* Displays the header for normal posts
*
* @param $heading
*
* @return string Formatted output in HTML
*/
function bornholm_the_post_header( $heading, $post ) {
if ( has_post_thumbnail() ) {
if ( ! is_single() ) { ?>
';
if ( ! is_single() ) { ?>
post_title;
if ( ! is_single() ) { ?>
';
}
/**
* Displays the header of a gallery.
* If there are $images, the function displays the title with an image.
* If not, only the title is displayed.
*
* @param $heading, $images, $size
*
* @return string Formatted output in HTML
*/
function bornholm_gallery_header( $heading, $images, $size, $post ) {
if ( $images ) {
bornholm_gallery_title( $heading, $images, $size, $post );
} else {
bornholm_post_title( $heading, $post );
}
}
/**
* Displays the title of a gallery with an image.
*
* @param $heading, $images, $size
*
* @return string Formatted output in HTML
*/
function bornholm_gallery_title( $heading, $images, $size, $post ) {
if ( $size != 'bornholm_large_gallery_image_for_single_view' ) { ?>
';
echo $post->post_title;
echo '' . $heading . '>';
}
bornholm_gallery_featured_image( $size, $images, $post );
if ( $size != 'bornholm_large_gallery_image_for_single_view' ) { ?>
ID, $size ); ?>
ID ) ) {
echo get_the_post_thumbnail( $post->ID, $size );
} else {
echo $image_img_tag;
} ?>
ID );
$counter = 0;
if ( has_post_thumbnail() ) {
bornholm_thumbnails_from_gallery_with_post_thumbnail( $post, $small_images, $counter, $size, $number_of_small_images );
} else {
bornholm_thumbnails_from_gallery_without_post_thumbnail( $small_images, $counter, $size, $number_of_small_images );
}
}
}
/**
* Displays the two first images from the gallery when a post thumbnail is set without displaying the
* thumbnail for a second time
*
* @param $post, $small_images, $counter, $size, $number_of_small_images
*
* @return string Formatted output in HTML
*/
function bornholm_thumbnails_from_gallery_with_post_thumbnail( $post, $small_images, $counter, $size, $number_of_small_images ) {
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
$image_list = '';
foreach ( $small_images as $single_image ) {
$single_image_url = wp_get_attachment_image_src( $single_image->ID );
if ( $counter >= $number_of_small_images ) {
break;
}
if ( $post_thumbnail[0] == $single_image_url[0] ) {
continue;
}
$image_list .= '' . wp_get_attachment_image( $single_image->ID, $size ) . ' ';
$counter ++;
}
$image_list .= ' ';
echo $image_list;
}
/**
* Displays the two first images from the gallery
*
* @param $small_images, $counter, $size, $number_of_small_images
*
* @return string Formatted output in HTML
*/
function bornholm_thumbnails_from_gallery_without_post_thumbnail( $small_images, $counter, $size, $number_of_small_images ) {
$image_list = '';
foreach ( $small_images as $single_image ) {
if ( $counter == 0 ) {
$counter ++;
continue;
}
if ( $counter > $number_of_small_images ) {
break;
}
$image_list .= '' . wp_get_attachment_image( $single_image->ID, $size ) . ' ';
$counter ++;
}
$image_list .= ' ';
echo $image_list;
}
/**
* Displays the number of gallery images
*
* @param $images
*
* @return string Formatted output in HTML
*/
function bornholm_gallery_image_number( $images ) {
if ( $images ) {
$total_images = count( $images ); ?>
%2$s photo.',
'This gallery contains %2$s photos .',
$total_images, 'bornholm' ),
'href="' . esc_url( get_permalink() )
. '"',
number_format_i18n( $total_images ) );
?>
name ); ?>
ID );
$hide_gallery_titles_on_alternative_front_page = get_theme_mod( 'hide_gallery_titles_on_alternative_front_page' );
$hide_gallery_titles_for_galleries_from_same_category = get_theme_mod( 'hide_gallery_titles_for_galleries_from_same_category' );
$hide_gallery_titles_on_portfolio_page = get_theme_mod( 'hide_gallery_titles_on_portfolio_page' );
$page_template = basename( get_page_template( $post->ID ) );
if ( ( $hide_gallery_titles_on_alternative_front_page == 1 && $page_template == 'alternative-home-page.php' ) ||
( $hide_gallery_titles_for_galleries_from_same_category == 1 && get_post_format() == 'gallery' && is_single() ) ||
$hide_gallery_titles_on_portfolio_page == 1 && $page_template == 'portfolio-page.php' ) {
bornholm_gallery_header( '', $images_child, 'thumbnail', $post );
} else {
bornholm_gallery_header( 'h3', $images_child, 'thumbnail', $post );
} ?>
cat_ID;
} else {
$category_ids .= ", $category_id->cat_ID";
}
$counter++;
}
return $category_ids;
}
/**
* Returns array with galleries (post format gallery) from given category
*
* @param $cat
*
* @return array
*/
function bornholm_galleries_args( $cat, $exclude_id ){
$args = array(
'category__in' => $cat->cat_ID,
'exclude' => "$exclude_id", // for the sidebar on a single gallery
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $cat->slug
),
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-gallery'
)
)
);
return $args;
}
/**
* Displays the galleries from one category
*
* @param $cat, $exclude_id ,$number_of_galleries, $heading, $title, $show_child_category_hierarchy
*
* @return string Formatted output in HTML
*/
function bornholm_get_galleries_from_category ( $cat, $exclude_id, $number_of_galleries, $heading, $title, $show_child_category_hierarchy ) {
$galleries_args = bornholm_galleries_args( $cat, $exclude_id );
$galleries = get_posts( $galleries_args );
if ( $galleries ) {
$total_galleries = count( $galleries );
$gallery_counter = 0; ?>
< class="category-title">>
term_id, 'category' );
if ( $category_children ) {
foreach ( $category_children as $cat_child ) {
$cat_child = get_category( $cat_child );
$child_galleries_args = bornholm_galleries_args( $cat_child, $exclude_id );
$child_galleries = get_posts( $child_galleries_args );
if ( $child_galleries ) {
$total_child_galleries = count( $child_galleries );
$gallery_child_counter = 0; ?>
name; ?>
<>>
0 ) {
if ( $total_galleries > $number_of_galleries ) {
$gallery_counter ++;
if ( $gallery_counter > $number_of_galleries ) {
bornholm_alternative_front_page_more_link( $cat );
break;
}
}
}
bornholm_alternative_front_page_gallery_teaser( $post );
}
}
/**
* Displays the footer for a post
*
* @return string Formatted output in HTML
*/
function bornholm_footer_meta() { ?>
0 ) {
bornholm_show_seperator( $show_sep ); ?>
">
0 ) {
bornholm_show_seperator( $show_sep ); ?>
">
· ', '' ); ?>
·
comment_type ) :
case 'pingback' :
case 'trackback' :
// Display trackbacks differently than normal comments.
?>
id="comment-">
', '' ); ?>
id="li-comment-">
ID;
global $wpdb;
$count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = ' '
AND comment_post_ID = $thePostID AND comment_approved='1'";
$co_number = $wpdb->get_var( $count );
if ( $co_number == 0 ) {
return $co_number;
} elseif ( $co_number == 1 ) {
$co_number = $co_number . __( ' Comment', 'bornholm' );
return $co_number;
} else {
$co_number = $co_number . __( ' Comments', 'bornholm' );
return $co_number;
}
}
/**
* Returns the Number of trackbacks for a post
*
* @return string
*/
function get_bornholm_trackback_count() {
global $post;
$thePostID = $post->ID;
global $wpdb;
$count = "SELECT COUNT(*) FROM $wpdb->comments
WHERE comment_type != ' '
AND comment_post_ID = $thePostID AND comment_approved='1'";
$tb_number = $wpdb->get_var( $count );
if ( $tb_number == 0 ) {
return $tb_number;
} elseif ( $tb_number == 1 ) {
$tb_number = $tb_number . __( ' Trackback', 'bornholm' );
return $tb_number;
} else {
$tb_number = $tb_number . __( ' Trackbacks', 'bornholm' );
return $tb_number;
}
}
/**
* Recent_Galleries widget class
*/
class Bornholm_Recent_Galleries extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'widget_recent_galleries',
'description' => _x( 'Your site’s most recent galleries.', 'Description of the recent galleries widget', 'bornholm' )
);
parent::__construct( 'recent-galleries', _x( 'Recent Galleries', 'Name of the recent galleries widget', 'bornholm' ), $widget_ops );
}
public function widget( $args, $instance ) {
$title = $instance['title'];
/** This filter is documented in wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 2;
if ( ! $number ) {
$number = 2;
}
/**
* Filter the arguments for the Recent Galleries widget
*
* @see WP_Query::get_posts()
*
* @param array $args An array of arguments used to retrieve the recent posts.
*/
$result = new WP_Query( apply_filters( 'widget_galleries_args', array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => 'post-format-gallery'
)
)
) ) );
if ( $result->have_posts() ) {
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
while ( $result->have_posts() ) {
$result->the_post();
$post = get_post( get_the_ID() );
$images = bornholm_get_gallery_images( $post->ID );
if ( $images ) {
$hide_gallery_titles_on_recent_galleries_widget = get_theme_mod( 'hide_gallery_titles_on_recent_galleries_widget' ); ?>
'widget_featured_galleries',
'description' => _x( 'Enter ids of galleries you want to feature.', 'Description of the featured galleries widget', 'bornholm' )
);
parent::__construct( 'featured-galleries', _x( 'Featured Galleries', 'Name of the featured galleries widget', 'bornholm' ), $widget_ops );
}
public function widget( $args, $instance ) {
$title = $instance['title'];
/** This filter is documented in wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$gallery_ids = $instance['gallery_ids'];
$gallery_ids = explode( ',', $gallery_ids );
$counter = 0;
foreach ( $gallery_ids as $gallery_id ) {
$post = get_post( $gallery_id );
$format = get_post_format( $gallery_id );
if ( $post && $format == 'gallery' ) {
if ( $counter == 0 ) {
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
}
$images = bornholm_get_gallery_images( $gallery_id );
$hide_gallery_titles_on_featured_galleries_widget = get_theme_mod( 'hide_gallery_titles_on_featured_galleries_widget' ); ?>
add_setting( 'number_of_galleries_from_same_category_on_single_gallery_page', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 3,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_positive_integer_or_null'
) );
$wp_customize->add_control( 'number_of_galleries_from_same_category_on_single_gallery_page', array(
'type' => 'number',
'priority'=>10,
'section'=>'gallery',
'label'=>__( 'Number of galleries from the same category to show in the single view of a gallery (0 if no galleries should be displayed)', 'bornholm' ),
));
$wp_customize->add_setting( 'hide_gallery_titles_for_galleries_from_same_category', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_checkbox'
) );
$wp_customize->add_control( 'hide_gallery_titles_for_galleries_from_same_category', array(
'type' => 'checkbox',
'priority'=>12,
'section'=>'gallery',
'label'=>__( 'Check if the titles of the galleries should be hidden for the galleries from the same category.', 'bornholm' ),
));
$wp_customize->add_setting( 'hide_gallery_titles_on_recent_galleries_widget', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_checkbox'
) );
$wp_customize->add_control( 'hide_gallery_titles_on_recent_galleries_widget', array(
'type' => 'checkbox',
'priority'=>12,
'section'=>'content',
'label'=>__( 'Check if the titles of the galleries should be hidden on the recent galleries widget.', 'bornholm' ),
));
$wp_customize->add_setting( 'hide_gallery_titles_on_featured_galleries_widget', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_checkbox'
) );
$wp_customize->add_control( 'hide_gallery_titles_on_featured_galleries_widget', array(
'type' => 'checkbox',
'priority'=>14,
'section'=>'content',
'label'=>__( 'Check if the titles of the galleries should be hidden on the featured galleries widget.', 'bornholm' ),
));
$wp_customize->add_setting( 'number_of_small_images_from_gallery_in_blog_view', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 2,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_positive_integer_or_null'
) );
$wp_customize->add_control( 'number_of_small_images_from_gallery_in_blog_view', array(
'type' => 'number',
'priority'=>10,
'section'=>'content',
'label'=>__( 'Number of small images from the gallery to show in the single view below the big image (0 if no small images should be displayed)', 'bornholm' ),
));
$wp_customize->add_setting( 'hierarchy_of_gallery_on_alternative_front_page', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_checkbox'
) );
$wp_customize->add_control( 'hierarchy_of_gallery_on_alternative_front_page', array(
'type' => 'checkbox',
'priority'=>10,
'section'=>'alternative_front_page',
'label'=>__( 'Check if the galleries from child categories should be displayed below the galleries of the parent category.', 'bornholm' ),
));
$wp_customize->add_setting( 'hide_gallery_titles_on_alternative_front_page', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_checkbox'
) );
$wp_customize->add_control( 'hide_gallery_titles_on_alternative_front_page', array(
'type' => 'checkbox',
'priority'=>12,
'section'=>'alternative_front_page',
'label'=>__( 'Check if the titles of the galleries should be hidden.', 'bornholm' ),
));
$wp_customize->add_setting( 'number_of_galleries_on_alternative_front_page', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 3,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_positive_integer_or_null'
) );
$wp_customize->add_control( 'number_of_galleries_on_alternative_front_page', array(
'type' => 'number',
'priority'=>14,
'section'=>'alternative_front_page',
'label'=>__( 'Number of galleries from every category to show', 'bornholm' ),
));
$wp_customize->add_setting( 'hide_gallery_titles_on_portfolio_page', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 0,
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_checkbox'
) );
$wp_customize->add_control( 'hide_gallery_titles_on_portfolio_page', array(
'type' => 'checkbox',
'priority'=>12,
'section'=>'portfolio_page',
'label'=>__( 'Check if the titles of the galleries should be hidden.', 'bornholm' ),
));
$wp_customize->add_setting( 'galleries_on_portfolio_page', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => 'standard',
'transport' => 'refresh',
'sanitize_callback' => 'bornholm_sanitize_radio'
) );
$wp_customize->add_control( 'galleries_on_portfolio_page', array(
'type' => 'radio',
'priority'=>10,
'section'=>'portfolio_page',
'label'=>__( 'Change the appearance of the galleries on the portfolio page', 'bornholm' ),
'choices' => array(
'standard' => 'Standard',
'portfolio_page_grouped_by_categories' => __('Display the galleries grouped by categories.', 'bornholm'),
'portfolio_page_grouped_by_categories_with_hierarchy' => __('Display the galleries grouped by categories with hierarchy (child categories below parent categories).', 'bornholm'),
),
));
$wp_customize->add_section( 'alternative_front_page' , array(
'title'=>_x( 'Alternative front page', 'Title of the alternative front page section in the Customizer', 'bornholm' ),
'priority'=>140,
'capability'=>'edit_theme_options'
));
$wp_customize->add_section( 'content' , array(
'title'=>_x( 'Content', 'Title of the content section in the Customizer', 'bornholm' ),
'priority'=>160,
'capability'=>'edit_theme_options'
));
$wp_customize->add_section( 'gallery' , array(
'title'=>_x( 'Gallery single view', 'Title of the Gallery single view section in the Customizer', 'bornholm' ),
'priority'=>130,
'capability'=>'edit_theme_options'
));
$wp_customize->add_section( 'portfolio_page' , array(
'title'=>_x( 'Portfolio Page', 'Title of the portfolio page section in the Customizer', 'bornholm' ),
'priority'=>150,
'capability'=>'edit_theme_options'
));
}
add_action( 'customize_register', 'bornholm_customize_register' );
function bornholm_customize_css() {
if ( get_theme_mod( 'header_textcolor' ) ) { ?>
= 0 ) {
return $value;
} else {
$value = 3;
return $value;
}
} else {
$value = 3;
return $value;
}
}
function bornholm_sanitize_checkbox( $value ) {
return $value;
}
function bornholm_sanitize_radio( $value ) {
if ( $value == '' ) {
$value = 'standard';
return $value;
} else {
return $value;
}
}