Skip to content

Commit 40570e6

Browse files
authored
Merge pull request #15 from OpenSourceOrg/add/9-last-modified-date
Add last modified date in the header
2 parents 296f12b + b60d001 commit 40570e6

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

themes/osi/inc/template-functions.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,14 @@ function get_license_search_query() {
169169
$query = sanitize_text_field( $query );
170170

171171
return $query;
172-
173172
}
174173
}
175174

176175

177176
// Meta Block Field Filter Date
178177
add_filter( 'meta_field_block_get_block_content', 'osi_filter_meta_block_date_output', 10, 4 );
179178
function osi_filter_meta_block_date_output( $content, $attributes, $block, $post_id ) {
180-
if ( is_numeric( $content ) && 8 == strlen( $content ) ) {
179+
if ( is_numeric( $content ) && 8 === strlen( $content ) ) {
181180
$content = DateTime::createFromFormat( 'Ymd', $content )->format( 'M Y' );
182181
}
183182
return $content;
@@ -187,17 +186,37 @@ function osi_filter_meta_block_date_output( $content, $attributes, $block, $post
187186
add_action( 'pre_get_posts', 'osi_press_mentions_by_publication_date' );
188187
function osi_press_mentions_by_publication_date( $query ) {
189188
if ( ! is_admin() && $query->is_main_query() ) {
190-
if( is_post_type_archive( 'press-mentions' ) ) {
189+
if ( is_post_type_archive( 'press-mentions' ) ) {
191190
$query->set( 'meta_key', 'date_of_publication' );
192191
$query->set( 'orderby', 'meta_value_num' );
193-
$query->set( 'order', 'DESC');
194-
$query->set( 'meta_query', array(
192+
$query->set( 'order', 'DESC' );
193+
$query->set(
194+
'meta_query',
195195
array(
196-
'key' => 'date_of_publication',
197-
'type' => 'numeric',
198-
)
199-
) );
196+
array(
197+
'key' => 'date_of_publication',
198+
'type' => 'numeric',
199+
),
200+
)
201+
);
200202
}
201203
}
202204
return $query;
203-
}
205+
}
206+
207+
/**
208+
* Renders the "Created" and "Last modified" string for a page.
209+
*/
210+
211+
function osi_the_page_dates() {
212+
if ( is_page() && ! is_home() && ! is_front_page() ) {
213+
$max_date = '2023-02-01'; // February 1, 2023
214+
$created = get_the_date( 'F j, Y' );
215+
$modified = get_the_modified_date( 'F j, Y' );
216+
217+
if ( strtotime( $created ) < strtotime( $max_date ) ) {
218+
// Post was created before the 'max date'.
219+
echo sprintf( '<h4 class="page_dates">Page created on %1$s | Last modified on %2$s</h4>', esc_html( $created ), esc_html( $modified ) );
220+
}
221+
}
222+
}

themes/osi/template-parts/content-page-no-header.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
<?php the_content(); ?>
1515
</div><!-- .entry-content -->
1616

17+
<?php osi_the_page_dates(); ?>
18+
1719
</article><!-- #post-<?php the_ID(); ?> -->

themes/osi/template-parts/header-featured-image.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
}
1111

12-
if( ! isset( $page_title ) ) {
12+
if ( ! isset( $page_title ) ) {
1313
$page_title = get_the_title();
1414
}
1515

@@ -28,6 +28,7 @@
2828
<div class="wp-block-cover alignfull has-neutral-dark-background-color has-background-dim-100 has-background-dim">
2929
<div class="wp-block-cover__inner-container">
3030
<?php echo ( ! empty( $page_title ) ) ? '<h1 class="entry-title page--title">' . esc_html( $page_title ) . '</h1>' : ''; ?>
31+
<?php osi_the_page_dates(); ?>
3132
</div>
3233
</div>
3334
</header>

0 commit comments

Comments
 (0)