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