-
Notifications
You must be signed in to change notification settings - Fork 1
/
display-posts-date-view.php
133 lines (112 loc) · 3.58 KB
/
display-posts-date-view.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
<?php
/**
* Plugin Name: Display Posts - Date View
* Plugin URI: https://github.com/billerickson/Display-Posts-Date-View
* Description: Display content broken down by month or year. You must have Display Posts installed.
* Version: 1.1.0
* Author: Bill Erickson
* Author URI: https://www.billerickson.net
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
class BE_DPS_Date_View {
/**
* Primary constructor
*
*/
function __construct() {
add_filter( 'display_posts_shortcode_wrapper_open', array( $this, 'opening_header' ), 10, 3 );
add_filter( 'display_posts_shortcode_wrapper_close', array( $this, 'closing_markup' ) );
add_filter( 'display_posts_shortcode_output', array( $this, 'post_output' ), 10, 11 );
}
/**
* Opening header
*
*/
function opening_header( $markup, $atts, $listing ) {
$markup = $this->heading( $listing->posts[0], $atts ) . $markup;
return $markup;
}
/**
* Closing markup
*
*/
function closing_markup( $markup ) {
global $dps_date_heading;
$dps_date_heading = false;
return $markup;
}
/**
* Post output
*
*/
function post_output( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
global $post, $dps_listing;
$heading = $this->heading( $post, $atts );
if( empty( $heading ) || 0 == $dps_listing->current_post )
return $output;
$wrapper = !empty( $atts['wrapper'] ) ? $atts['wrapper'] : 'ul';
$wrapper_class = !empty( $atts['wrapper_class'] ) ? $atts['wrapper_class'] : 'display-posts-listing';
$output = '</' . $wrapper . '>' . $heading . '<' . $wrapper . ' class="' . $wrapper_class . '">' . $output;
return $output;
}
/**
* Heading
*
*/
function heading( $post, $atts ) {
if( empty( $post ) || is_wp_error( $post ) )
return;
$format = false;
if( !empty( $atts['display_by_day'] ) && true === filter_var( $atts['display_by_day'], FILTER_VALIDATE_BOOLEAN ) ) {
$format = apply_filters( 'display_posts_date_view_day_format', 'F j Y' );
}elseif( !empty( $atts['display_by_month'] ) && true === filter_var( $atts['display_by_month'], FILTER_VALIDATE_BOOLEAN ) ) {
$format = apply_filters( 'display_posts_date_view_month_format', 'F Y' );
} elseif( !empty( $atts['display_by_year'] ) && true === filter_var( $atts['display_by_year'], FILTER_VALIDATE_BOOLEAN ) ) {
$format = apply_filters( 'display_posts_date_view_year_format', 'Y' );
}
if( empty( $format ) )
return;
global $dps_date_heading;
$date = get_the_date( $format, $post->ID );
if( $date !== $dps_date_heading ) {
$dps_date_heading = $date;
return $this->heading_open() . $date . $this->heading_close();
}
}
/**
* Heading Open
*
*/
function heading_open() {
return '<' . $this->heading_tag() . ' class="' . $this->heading_class() . '">';
}
/**
* Heading Close
*
*/
function heading_close() {
return '</' . $this->heading_tag() . '>';
}
/**
* Heading Tag
*
*/
function heading_tag() {
return apply_filters( 'display_posts_date_view_heading_tag', 'h4' );
}
/**
* Heading class
*
*/
function heading_class() {
return apply_filters( 'display_posts_date_view_heading_class', 'display-posts-date' );
}
}
new BE_DPS_Date_View;