css
4 years ago
images
12 years ago
img
13 years ago
js
4 years ago
archiveorg-book.php
5 years ago
archiveorg.php
5 years ago
archives.php
5 years ago
bandcamp.php
5 years ago
brightcove.php
5 years ago
cartodb.php
5 years ago
class.filter-embedded-html-objects.php
3 years ago
codepen.php
5 years ago
crowdsignal.php
3 years ago
dailymotion.php
3 years ago
descript.php
4 years ago
facebook.php
3 years ago
flatio.php
5 years ago
flickr.php
5 years ago
getty.php
3 years ago
gist.php
5 years ago
googleapps.php
3 years ago
googlemaps.php
5 years ago
googleplus.php
5 years ago
gravatar.php
3 years ago
houzz.php
5 years ago
inline-pdfs.php
4 years ago
instagram.php
3 years ago
kickstarter.php
3 years ago
mailchimp.php
3 years ago
medium.php
3 years ago
mixcloud.php
3 years ago
others.php
3 years ago
pinterest.php
5 years ago
presentations.php
3 years ago
quiz.php
4 years ago
recipe.php
3 years ago
scribd.php
5 years ago
sitemap.php
5 years ago
slideshare.php
5 years ago
slideshow.php
3 years ago
smartframe.php
4 years ago
soundcloud.php
3 years ago
spotify.php
4 years ago
ted.php
5 years ago
tweet.php
5 years ago
twitchtv.php
5 years ago
twitter-timeline.php
5 years ago
unavailable.php
3 years ago
untappd-menu.php
3 years ago
upcoming-events.php
3 years ago
ustream.php
5 years ago
videopress.php
4 years ago
vimeo.php
3 years ago
vine.php
5 years ago
vr.php
3 years ago
wordads.php
5 years ago
wufoo.php
3 years ago
youtube.php
3 years ago
archives.php
85 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Archives shortcode |
| 4 | * |
| 5 | * @author bubel & nickmomrik |
| 6 | * [archives limit=10] |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | add_shortcode( 'archives', 'archives_shortcode' ); |
| 12 | |
| 13 | /** |
| 14 | * Display Archives shortcode. |
| 15 | * |
| 16 | * @param array $atts Shortcode attributes. |
| 17 | */ |
| 18 | function archives_shortcode( $atts ) { |
| 19 | if ( is_feed() ) { |
| 20 | return '[archives]'; |
| 21 | } |
| 22 | |
| 23 | global $allowedposttags; |
| 24 | |
| 25 | $default_atts = array( |
| 26 | 'type' => 'postbypost', |
| 27 | 'limit' => '', |
| 28 | 'format' => 'html', |
| 29 | 'showcount' => false, |
| 30 | 'before' => '', |
| 31 | 'after' => '', |
| 32 | 'order' => 'desc', |
| 33 | ); |
| 34 | |
| 35 | $attr = shortcode_atts( $default_atts, $atts, 'archives' ); |
| 36 | |
| 37 | if ( ! in_array( $attr['type'], array( 'yearly', 'monthly', 'daily', 'weekly', 'postbypost' ), true ) ) { |
| 38 | $attr['type'] = 'postbypost'; |
| 39 | } |
| 40 | |
| 41 | if ( ! in_array( $attr['format'], array( 'html', 'option', 'custom' ), true ) ) { |
| 42 | $attr['format'] = 'html'; |
| 43 | } |
| 44 | |
| 45 | $limit = (int) $attr['limit']; |
| 46 | // A Limit of 0 makes no sense so revert back to the default. |
| 47 | if ( empty( $limit ) ) { |
| 48 | $limit = ''; |
| 49 | } |
| 50 | |
| 51 | $showcount = ( false !== $attr['showcount'] && 'false' !== $attr['showcount'] ) ? true : false; |
| 52 | $before = wp_kses( $attr['before'], $allowedposttags ); |
| 53 | $after = wp_kses( $attr['after'], $allowedposttags ); |
| 54 | |
| 55 | // Get the archives. |
| 56 | $archives = wp_get_archives( |
| 57 | array( |
| 58 | 'type' => $attr['type'], |
| 59 | 'limit' => $limit, |
| 60 | 'format' => $attr['format'], |
| 61 | 'echo' => false, |
| 62 | 'show_post_count' => $showcount, |
| 63 | 'before' => $before, |
| 64 | 'after' => $after, |
| 65 | ) |
| 66 | ); |
| 67 | |
| 68 | if ( 'asc' === $attr['order'] ) { |
| 69 | $archives = implode( "\n", array_reverse( explode( "\n", $archives ) ) ); |
| 70 | } |
| 71 | |
| 72 | // Check to see if there are any archives. |
| 73 | if ( empty( $archives ) ) { |
| 74 | $archives = '<p>' . __( 'Your blog does not currently have any published posts.', 'jetpack' ) . '</p>'; |
| 75 | } elseif ( 'option' === $attr['format'] ) { |
| 76 | $is_amp = class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request(); |
| 77 | $change_attribute = $is_amp ? 'on="change:AMP.navigateTo(url=event.value)"' : 'onchange="document.location.href=this.options[this.selectedIndex].value;"'; |
| 78 | $archives = '<select name="archive-dropdown" ' . $change_attribute . '><option value="' . get_permalink() . '">--</option>' . $archives . '</select>'; |
| 79 | } elseif ( 'html' === $attr['format'] ) { |
| 80 | $archives = '<ul>' . $archives . '</ul>'; |
| 81 | } |
| 82 | |
| 83 | return $archives; |
| 84 | } |
| 85 |