SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | /** | |
3 | * | |
4 | Template Name: Home Page | |
5 | * | |
6 | * @package WordPress | |
7 | * @subpackage Toolbox | |
8 | * @since Toolbox 0.1 | |
9 | */ | |
10 | ||
11 | ||
12 | get_header(); ?> | |
13 | ||
14 | <div id="primary" class="full-width"> | |
15 | <div id="content" role="main"> | |
16 | <?php $pageCheck = $post->ID; ?> | |
17 | <?php if ( get_post_meta($pageCheck, '728 x 90', true) ) :?> | |
18 | <div class="ad id-<?php echo $pageCheck; ?>"> | |
19 | <?php echo get_post_meta($pageCheck, '728 x 90', true); ?> | |
20 | </div> | |
21 | <? endif ; ?> | |
22 | <div id="hero"> | |
23 | <script type="text/javascript"> | |
24 | jQuery(document).ready(function(){ | |
25 | jQuery("#featured-slider").easySlider({ | |
26 | hoverPause: true, | |
27 | auto: true, | |
28 | continuous: true, | |
29 | speed: 400, | |
30 | pause: 6000, | |
31 | numeric: true, | |
32 | numericId: 'controls' | |
33 | }); | |
34 | }); | |
35 | </script> | |
36 | <div id="featured-slider"> | |
37 | <ul> | |
38 | <?php | |
39 | $sliderargs = array( | |
40 | 'posts_per_page' => 5, // get four posts for each section we want to show | |
41 | 'post_type' => array('recipe','la_foodie','nyc_foodie','mixology','chefs_table')); | |
42 | $my_query = new WP_Query($sliderargs); ?> | |
43 | <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> | |
44 | <li> | |
45 | <div class="left"><?php $alt_tag = get_the_title($post->ID); ?> | |
46 | <?php if ( has_post_thumbnail() ) { ?> | |
47 | <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> | |
48 | <?php the_post_thumbnail('featured-image', array('alt' => 'View the Recipe', 'title' => $alt_tag )); ?> | |
49 | </a> | |
50 | </div> | |
51 | <?php } ?> | |
52 | <div class="right"> | |
53 | <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> | |
54 | <p><?php new_excerpt(180); ?></p> | |
55 | <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">Read More ></a> | |
56 | </div> | |
57 | </li> | |
58 | <?php endwhile; ?> | |
59 | </ul> | |
60 | </div> | |
61 | </div> | |
62 | <?php | |
63 | ||
64 | global $post; | |
65 | ||
66 | $total_sections = 4; // the total number of sections that you want in your slider | |
67 | ||
68 | $args = array( | |
69 | 'posts_per_page' => $total_sections * 4, // get four posts for each section we want to show | |
70 | 'post_type' => array('post','recipe','la_foodie','nyc_foodie','mixology','chefs_table') | |
71 | ||
72 | ); | |
73 | ||
74 | ||
75 | ||
76 | $carousel_query = new WP_Query($args); | |
77 | ||
78 | if ($carousel_query->have_posts()) { | |
79 | $slider = array(); | |
80 | $section = array(); | |
81 | ||
82 | ||
83 | while ($carousel_query->have_posts()) { | |
84 | $carousel_query->the_post(); | |
85 | ||
86 | ||
87 | ||
88 | // Not sure what you actually want to put in the grid for each post...so edit here as you need to... | |
89 | ||
90 | $html = sprintf('<h2 class="entry-title"><a href="%1$s" title="%2$s">%2$s</a></h2><a href="%1$s" title="%2$s">%3$s</a>', | |
91 | get_permalink(), get_the_title(),get_the_post_thumbnail( $post->ID, 'thumbnail')); | |
92 | $section[] = $html; | |
93 | ||
94 | ||
95 | ||
96 | ||
97 | // for the third and sixth array slots, put in ad code | |
98 | ||
99 | // since our original WP_Query pulled randomly, then the actual ads that get pulled for | |
100 | ||
101 | // these slots will be...random! | |
102 | ||
103 | if( count($section) == 2 || count($section) == 5 ) { | |
104 | ||
105 | $fields = array('300 x 250 Bottom', '300 x 250 Top'); | |
106 | $adcode = get_post_meta( $post->ID, $fields[array_rand($fields, 1 )], true ); | |
107 | $section[] = $adcode; | |
108 | ||
109 | } | |
110 | ||
111 | ||
112 | ||
113 | // If we've got a group of 6.... | |
114 | ||
115 | if( count($section) == 6 ) { | |
116 | ||
117 | shuffle($section); // We need to mix up the six so that the ads could be anywhere | |
118 | ||
119 | $slider[] = $section; // store the group in our slider list | |
120 | ||
121 | $section = array(); // and reset the section | |
122 | ||
123 | } | |
124 | ||
125 | } | |
126 | ||
127 | ||
128 | ||
129 | // This is belt and braces since you should have pulled exactly the | |
130 | ||
131 | // right amount of posts, but if you haven't then the while loop will | |
132 | ||
133 | // have bailed out before the group got added to the slider | |
134 | ||
135 | if( !empty($section) ) { | |
136 | ||
137 | shuffle($section); // We need to mix up the six so that the ads could be anywhere | |
138 | ||
139 | $slider[] = $section; | |
140 | ||
141 | } | |
142 | ||
143 | ||
144 | ||
145 | // By now you should have an array of size $total_sections, each with an array of 6 inside | |
146 | ||
147 | // So you can do you html loop | |
148 | ||
149 | ||
150 | $i = 1; | |
151 | ||
152 | echo '<ul id="slider">'; | |
153 | ||
154 | foreach( $slider as $section ) { | |
155 | ||
156 | echo '<li id="section_'.$i.'"><ul>'; | |
157 | ||
158 | ||
159 | ||
160 | foreach( $section as $box ) { | |
161 | ||
162 | echo '<li class="section_box">'.$box.'</li>'; | |
163 | ||
164 | } | |
165 | ||
166 | ||
167 | ||
168 | echo '</ul></li>'; | |
169 | ||
170 | $i++; | |
171 | ||
172 | } | |
173 | ||
174 | echo '</ul>'; | |
175 | ||
176 | } | |
177 | ||
178 | ?> | |
179 | ||
180 | ||
181 | ||
182 | ||
183 | ||
184 | ||
185 | </div><!-- #content --> | |
186 | </div><!-- #primary --> | |
187 | ||
188 | <?php get_footer(); ?> |