-
Notifications
You must be signed in to change notification settings - Fork 11
/
front-page.php
160 lines (109 loc) · 3.21 KB
/
front-page.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
* The template for displaying the front page of the site.
*
* @package OKFNWP
*/
get_header();
global $post;
if ( is_singular() && ! empty( $post->post_content ) ) :
// Show static page content.
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<div class="main col-md-12">
<?php get_template_part( 'content', 'page' ); ?>
</div>
<?php
endwhile;
endif;
else :
// Show dynamic homepage content.
?>
<div class="main col-lg-8">
<?php
// This is currently the most flexible approach for the Featured post category.
// Get the category object by its path/slug.
if ( ! isset( $okf_featured_cat ) ) {
$okf_featured_cat = get_category_by_path( 'featured' );
}
// Check if the Home page is paginated and skip the featured posts rendering
// on any page after the first one.
if ( isset( $paged, $okf_featured_cat ) && $paged < 2 ) :
$okf_all_sticky_posts = get_option( 'sticky_posts' );
// Show Sticky Posts only when at least one Sticky Post exists.
if ( ! empty( $okf_all_sticky_posts ) ) :
$okf_sticky_post = new WP_Query(
array(
'post__in' => $okf_all_sticky_posts,
'post__not_in' => $okf_rendered_posts_ids,
)
);
if ( $okf_sticky_post->have_posts() ) :
while ( $okf_sticky_post->have_posts() ) :
$okf_sticky_post->the_post();
get_template_part( 'content', 'featured' );
endwhile;
wp_reset_postdata();
endif;
endif;
// Get Featured posts.
$okf_featured = new WP_Query(
array(
'cat' => $okf_featured_cat->term_id,
'posts_per_page' => 1,
'post__not_in' => $okf_rendered_posts_ids,
)
);
if ( $okf_featured->have_posts() ) :
while ( $okf_featured->have_posts() ) :
$okf_featured->the_post();
get_template_part( 'content', 'featured' );
endwhile;
wp_reset_postdata();
endif;
/*
@ignore Don't test commented out code.
else:
?>
<div class="alert alert-warning"><p>
<?php _e("Sorry, the Featured post category is not available and this content cannot be rendered.", 'okfnwp'); ?>
</p></div>
<?php
*/endif;
// Get the most recent post for each of the featured categories defined in
// functions.php via okfn_global_vars().
global $okf_frontpage_categories;
global $okf_rendered_posts_ids;
if ( $okf_frontpage_categories ) :
?>
<div class="row">
<?php
$okf_args = array(
'category__in' => $okf_frontpage_categories,
'posts_per_page' => 10,
'post_status' => 'publish', // Required! so that no Private posts are listed for logged in users.
'post__not_in' => $okf_rendered_posts_ids,
);
// Query the most recent post from each of the featured categories,
// while checking and remembering already rendered posts.
$okf_featured_post = new WP_Query( $okf_args );
if ( $okf_featured_post->have_posts() ) :
while ( $okf_featured_post->have_posts() ) :
$okf_featured_post->the_post();
// Check if the current post has already been rendered on the page.
if ( ! okfn_is_post_rendered( $post ) ) :
get_template_part( 'content', 'front' );
endif;
endwhile;
wp_reset_postdata();
endif;
?>
</div>
<?php endif; ?>
</div>
<?php
get_sidebar();
endif;
get_footer();