-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhomepage.php
50 lines (45 loc) · 1.5 KB
/
homepage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
Template Name: Home Page
Description: A Template for the Website homepage.
*/
add_filter( 'wp_title', 'baw_hack_wp_title_for_home' );
function baw_hack_wp_title_for_home( $title )
{
if( empty( $title ) && ( is_home() || is_front_page() ) ) {
return __( 'Home', 'theme_domain' );
}
return $title;
}
?>
<?php
/*
Generate a random backround from the list below.
*/
$directory = get_template_directory_uri().'/images/';
?>
<?php get_header(); ?>
<h1 class="sr-only"><?php bloginfo('name')?> Homepage</h1>
<div id="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(__('(more...)')); ?>
<?php endwhile; else: ?>
<?php _e('Sorry, no posts matched your criteria.'); ?><?php endif; ?>
</div>
<script type="text/javascript">
$(document).ready(function() {
<?php // hooks into advanced custom fields to allow new background images to be added in the wordpress editor
if(get_post_meta($post->ID, 'background_images', true)):
$background_images = get_post_meta($post->ID, 'background_images', true);
echo "let images = [$background_images];";
echo "images = images[Math.floor(Math.random() * images.length)];";
else:
$directory = get_template_directory_uri().'/images/';
echo "let directory = '$directory';";
echo "let images = '$directory' + 'bg-11-hitt-new-entrance.jpg';";
endif;
?>
$('.background-image').css({'background-image': 'url('+ images +')'});
});
</script>
<?php get_footer(); ?>