__( '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( 'widgets_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 the content with customized more link
*
* @return string Formatted output in HTML
*/
function bornholm_the_content() {
$text = _x( 'Continue reading “%s”', 's = post title', 'bornholm' );
$more = sprintf( $text, esc_html( 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', '//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() ) { ?>
';
the_title();
echo '' . $heading . '>'; ?>
';
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 esc_html( $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-front-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() { ?>
">
">
· ', '' ); ?>
·
comment_type ) :
case 'pingback' :
case 'trackback' :
// Display trackbacks differently than normal comments.
?>
id="comment-">
', '' ) ); ?>
id="li-comment-">
ID;
global $wpdb;
$co_number = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = %s
AND comment_post_ID = %d AND comment_approved = %d", ' ', $the_post_id, 1 ) );
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;
$the_post_id = $post->ID;
global $wpdb;
$tb_number = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type != %s
AND comment_post_ID = %d AND comment_approved = %d", ' ', $the_post_id, 1 ) );
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;
}
}
require get_template_directory() . '/inc/class-recent-galleries.php';
require get_template_directory() . '/inc/class-featured-galleries.php';
function register_bornholm_widgets() {
register_widget( 'Bornholm_Recent_Galleries' );
register_widget( 'Bornholm_Featured_Galleries' );
}
add_action( 'widgets_init', 'register_bornholm_widgets' );
require get_template_directory() . '/inc/customizer.php';