-
Notifications
You must be signed in to change notification settings - Fork 0
/
template-pages-listing.php
136 lines (99 loc) · 3.5 KB
/
template-pages-listing.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
<?php
/**
* Template Name: Pages listing
*
* Supports the following meta data keys:
* - hide_in_pages_listing - hides a child page from the pages listing.
*
* @package author-hemingway-child-theme
*/
?>
<?php get_header(); ?>
<div class="wrapper section-inner">
<div class="content full-width">
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<div class="posts">
<div class="post">
<div class="post-header">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
<h2 class="post-title"><?php the_title(); ?></h2>
</a>
</div> <!-- /post-header -->
<div class="post-content">
<?php the_content(); ?>
<?php if ( current_user_can( 'manage_options' ) ) : ?>
<p><?php edit_post_link( __( 'Edit', 'hemingway' ) ); ?></p>
<?php endif; ?>
<div class="clear"></div>
</div> <!-- /post-content -->
</div> <!-- /post -->
<div class="tiles-container" id="tiles-container">
<?php
// For reference: https://codex.wordpress.org/Function_Reference/get_pages.
$child_pages = get_pages( array(
'child_of' => $post->ID,
'sort_column' => 'menu_order',
'sort_order' => 'asc',
) );
foreach ( $child_pages as $page ) {
$content = $page->post_content;
if ( ! $content || true === bool_from_yn( get_post_meta( $page->ID, 'hide_in_pages_listing', true ) ) ) { // Check for empty page.
continue;
}
$content = apply_filters( 'the_content', $content );
?>
<a class="tile-outer" href="<?php echo esc_url( get_page_link( $page->ID ) ); ?>">
<div class="tile-inner">
<?php if ( has_post_thumbnail( $page->ID ) ) : ?>
<div class="tile-image">
<?php echo get_the_post_thumbnail( $page, 'category-thumb' ); ?>
</div> <!-- /featured-media -->
<?php endif; ?>
</div>
</a>
<?php } // end foreach child_pages ?>
</div> <!-- /tiles-container -->
<?php if ( comments_open() ) : ?>
<?php comments_template( '', true ); ?>
<?php endif; ?>
</div> <!-- /posts -->
<?php endwhile; else : ?>
<p><?php esc_html_e( "We couldn't find any posts that matched your query. Please try again.", 'hemingway' ); ?></p>
<?php endif; ?>
</div> <!-- /content -->
</div> <!-- /wrapper section-inner -->
<?php get_footer(); ?>
<script>
// progressive enhancement workaround for last row of justify-content: space-between
// add additional empty tiles so that last row appears left aligned
// adjusted very slightly for this template from the code snippet by Lewis Walsh
// thanks to: https://lewiswalsh.com/flexbox-space-between-and-the-last-row/
//
// there will technically be flicker on page load using this, but since the tiles begin
// 'beneath the fold', this shouldn't be visible to the user
function checkCount( currentTotal, next ) {
if ( currentTotal % 6 ) { // Divisible by 3
currentTotal += 1; // Proper way to do ++
checkCount( currentTotal, next ); // Recursion!
} else {
next( currentTotal );
}
}
function addDummyElementsToCards( containerId ) {
var container = document.getElementById( containerId );
var cardCount = container.children.length;
checkCount(cardCount, function( finalCount ) {
var dummyElement;
for( i=0; i<( finalCount - cardCount ); i++ ) {
dummyElement = document.createElement( 'div' );
dummyElement.className = 'tile-outer';
container.appendChild(dummyElement);
}
});
}
addDummyElementsToCards('tiles-container');
</script>