'
) );
/**
* Register the sidebar that is visible on single view of gallery posts.
*/
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' => '
',
'after_title' => '
'
) );
/**
* Register the sidebar that is displayed in the top area of the footer.
*/
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' => '
',
'after_title' => '
'
) );
/**
* Register the sidebar that is displayed below the top footer sidebar.
*/
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' => '
',
) );
}
/**
* Displays the content with customized more link
*
* @return void 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 string $link The read more link.
*
* @return string
*/
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' );
}
/**
* Include the menu script.
*/
wp_enqueue_script( 'bornholm-menu', get_template_directory_uri() . '/js/menu.js', array( 'jquery' ), false, true );
/**
* Include the lightbox script.
*/
wp_enqueue_script( 'bornholm-lightbox', get_template_directory_uri() . '/js/lightbox.js', array( 'jquery' ), false, true );
/**
* Include the stylesheet.
*/
wp_enqueue_style( 'bornholm-style', get_template_directory_uri() . '/css/bornholm.css', array(), null );
}
add_action( 'wp_enqueue_scripts', 'bornholm_scripts_styles' );
/**
* Fetch image post objects for all gallery images in a post.
*
* @param int $post_id ID of the post.
*
* @return array
*/
function bornholm_get_gallery_images( $post_id ) {
/**
* Get the post data.
*/
$post = get_post( $post_id );
/**
* Check if we do not have a post or the post content is empty.
*/
if ( ! $post || empty ( $post->post_content ) ) {
return array();
}
/**
* Get the post galleries as an array.
*/
$galleries = get_post_galleries( $post, false );
/**
* Check if we have galleries, otherwise return an empty array.
*/
if ( empty ( $galleries ) ) {
return array();
}
/**
* Create empty IDs array.
*/
$ids = array();
/**
* Loop the galleries.
*/
foreach ( $galleries as $gallery ) {
/**
* Insert IDs of gallery images into $ids.
*/
if ( ! empty ( $gallery['ids'] ) ) {
$ids = array_merge( $ids, explode( ',', $gallery['ids'] ) );
}
}
/**
* Remove IDs of multiple used images.
*/
$ids = array_unique( $ids );
/**
* Check if $ids is empty, so we do not have any gallery images (possible if [gallery] is used
* without ids argument.
*/
if ( empty ( $ids ) ) {
/**
* Get the images that are uploaded to the post.
*/
$attachments = get_children( array(
'post_parent' => $post_id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order',
) );
/**
* Return empty array, if we do not have any attachments.
*/
if ( empty ( $attachments ) ) {
return array();
}
}
/**
* Get the post data of the gallery images.
*/
$images = get_posts(
array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'post__in',
'numberposts' => 999,
'include' => $ids
)
);
/**
* Check if $images and $attachments is empty and return empty array.
* If only $images is empty, set $images to the value of $attachments.
*/
if ( ! $images && ! $attachments ) {
return array();
} elseif ( ! $images ) {
$images = $attachments;
}
return $images;
}
/**
* Displays the header for normal posts
*
* @param string $heading Heading level.
* @param object $post Post object.
*
* @return void
*/
function bornholm_the_post_header( $heading, $post ) {
/**
* Check if we have a post thumbnail.
*/
if ( has_post_thumbnail() ) {
/**
* Link the title if we are not on single view.
*/
if ( ! is_single() ) { ?>
';
the_title();
echo '' . $heading . '>';
/**
* Display the post thumbnail
*/
?>
';
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 string $heading Level of heading.
* @param array $images Array of gallery images.
* @param string $size Image size.
* @param object $post Post object.
*
* @return void
*/
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 string $heading Heading level.
* @param array $images Gallery images.
* @param string $size Image size.
* @param object $post Post object.
*
* @return void
*/
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 ) );
$image_list = '
';
echo $image_list;
}
/**
* Displays the first images from the gallery
*
* @param array $small_images Small images.
* @param int $counter Counter.
* @param string $size Image size.
* @param int $number_of_small_images Number of small images.
*
* @return void
*/
function bornholm_thumbnails_from_gallery_without_post_thumbnail( $small_images, $counter, $size, $number_of_small_images ) {
$image_list = '