function smarty_get_archives_link($params) { $format = 'html'; $before = ''; $after = ''; extract($params); return get_archives_link($url, $text, $format, $before, $after); }
function get_blix_archive($show_comment_count = 0, $before = '<h4>', $after = '</h4>', $year = 0, $post_type = 'post', $limit = 100) { global $month, $wpdb; $result = ''; if ($year) { $AND_year = " AND YEAR(post_date)='{$year}'"; } if ($limit) { $LIMIT = " LIMIT {$limit}"; } $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_type='{$post_type}' {$AND_year} AND post_status='publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); $text = sprintf('%s %d', $month[zeroise($arcresult->month, 2)], $arcresult->year); $result .= get_archives_link($url, $text, '', $before, $after); $thismonth = zeroise($arcresult->month, 2); $thisyear = $arcresult->year; $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status, guid, comment_count FROM " . $wpdb->posts . " WHERE post_date LIKE '{$thisyear}-{$thismonth}-%' AND post_status='publish' AND post_type='{$post_type}' AND post_password='' ORDER BY post_date DESC {$LIMIT}"); if ($arcresults2) { $result .= "<ul class=\"postspermonth\">\n"; foreach ($arcresults2 as $arcresult2) { if ($arcresult2->post_date != '0000-00-00 00:00:00') { $url = get_permalink($arcresult2->ID); //$arcresult2->guid; $arc_title = $arcresult2->post_title; if ($arc_title) { $text = strip_tags($arc_title); } else { $text = $arcresult2->ID; } $result .= "<li>" . get_archives_link($url, $text, ''); if ($show_comment_count) { $cc = $arcresult2->comment_count; if ($arcresult2->comment_status == "open" or $comments_count > 0) { $result .= " ({$cc})"; } } $result .= "</li>\n"; } } $result .= "</ul>\n"; } } } return $result; }
function dt_archives_shortcode() { global $month, $wpdb, $wp_version; // a mysql query to get the list of distinct years and months that posts have been created $sql = 'SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM ' . $wpdb->posts . ' WHERE post_status="publish" AND post_type="post" AND post_password="" GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC'; // use get_results to do a query directly on the database $archiveSummary = $wpdb->get_results($sql); // if there are any posts if ($archiveSummary) { $output = '<div class="archives">'; // loop through the posts foreach ($archiveSummary as $date) { // reset the query variable unset($bmWp); // create a new query variable for the current month and year combination $bmWp = new WP_Query('year=' . $date->year . '&monthnum=' . zeroise($date->month, 2) . '&posts_per_page=-1'); // if there are any posts for that month display them if ($bmWp->have_posts()) { // display the archives heading $url = get_month_link($date->year, $date->month); $text = $month[zeroise($date->month, 2)] . ' ' . $date->year; $output .= get_archives_link($url, $text, '', '<h3>', '</h3>'); $output .= '<ul class="postspermonth">'; // display an unordered list of posts for the current month while ($bmWp->have_posts()) { $bmWp->the_post(); $output .= '<li><a href="' . get_permalink($bmWp->post) . '" title="' . esc_html($text, 1) . '">' . wptexturize($bmWp->post->post_title) . '</a></li>'; } $output .= '</ul>'; } } $output .= '</div><!-- .archives -->'; return $output; } }
/** * Function BX_archive * ------------------------------------------------------ * This function is based on WP's built-in get_archives() * It outputs the following: * * <h3><a href="link">Month Year</a></h3> * <ul class="postspermonth"> * <li><a href="link">Post title</a> (Comment count)</li> * [..] * </ul> */ function BX_archive() { global $month, $wpdb; $now = current_time('mysql'); $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_date <'" . $now . "' AND post_status='publish' AND post_password='' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); $text = sprintf('%s %d', $month[zeroise($arcresult->month, 2)], $arcresult->year); echo get_archives_link($url, $text, '', '<h3>', '</h3>'); $thismonth = zeroise($arcresult->month, 2); $thisyear = $arcresult->year; $arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status FROM " . $wpdb->posts . " WHERE post_date LIKE '{$thisyear}-{$thismonth}-%' AND post_status='publish' AND post_password='' ORDER BY post_date DESC"); if ($arcresults2) { echo "<ul class=\"postspermonth\">\n"; foreach ($arcresults2 as $arcresult2) { if ($arcresult2->post_date != '0000-00-00 00:00:00') { $url = get_permalink($arcresult2->ID); $arc_title = $arcresult2->post_title; if ($arc_title) { $text = strip_tags($arc_title); } else { $text = $arcresult2->ID; } echo "<li>" . get_archives_link($url, $text, ''); $comments = mysql_query("SELECT * FROM " . $wpdb->comments . " WHERE comment_post_ID=" . $arcresult2->ID); $comments_count = mysql_num_rows($comments); if ($arcresult2->comment_status == "open" or $comments_count > 0) { echo ' (' . $comments_count . ')'; } echo "</li>\n"; } } echo "</ul>\n"; } } } }
function wp_custom_archive($args = '') { global $wpdb, $wp_locale; $defaults = array('limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if ('' != $limit) { $limit = absint($limit); $limit = ' LIMIT ' . $limit; } // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } //filters $where = apply_filters('customarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r); $join = apply_filters('customarchives_join', "", $r); $output = '<ul>'; $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC {$limit}"; $key = md5($query); $cache = wp_cache_get('wp_custom_archive', 'general'); if (!isset($cache[$key])) { $arcresults = $wpdb->get_results($query); $cache[$key] = $arcresults; wp_cache_set('wp_custom_archive', $cache, 'general'); } else { $arcresults = $cache[$key]; } if ($arcresults) { $afterafter = $after; foreach ((array) $arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%s'), $wp_locale->get_month($arcresult->month)); $year_text = sprintf('<li>%d</li>', $arcresult->year); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } $output .= $arcresult->year != $temp_year ? $year_text : ''; $output .= get_archives_link($url, $text, $format, $before, $after); $temp_year = $arcresult->year; } } $output .= '</ul>'; if ($echo) { echo $output; } else { return $output; } }
/** * Adds the items to the trail items array for week archives. * * @since 0.6.0 * @access public * @return void */ public function do_week_archive_items() { /* Add $wp_rewrite->front to the trail. */ $this->do_rewrite_front_items(); /* Get the year and week. */ $year = get_the_time($this->args['labels']['archive_year']); $week = sprintf($this->args['labels']['archive_week'], date_i18n('W', get_the_time('U'))); /* Add the year item. */ $this->items[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . esc_attr($year) . '" rel="v:url" property="v:title">' . $year . '</a>'; /* Add the week item. */ if (is_paged()) { $this->items[] = get_archives_link(add_query_arg(array('m' => get_the_time('Y'), 'w' => get_the_time('W')), home_url()), $week, false); } elseif (true === $this->args['show_title']) { $this->items[] = $week; } }
function get_archives($type = '', $limit = '', $format = 'html', $before = "", $after = "", $show_post_count = false) { global $dateformat, $time_difference, $siteurl, $wp_id; global $month, $wpdb, $wp_month_format; if ('' == $type) { $type = get_settings('archive_mode'); } if ('' != $limit) { $limit = (int) $limit; $limit = " LIMIT {$limit}"; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // archive link url $archive_link_m = $siteurl . '/index.php?m='; # monthly archive; $archive_link_w = $siteurl . '/index.php?w='; # weekly archive; $archive_link_p = $siteurl . '/index.php?p='; # post-by-post archive; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = $dateformat; $archive_week_start_date_format = $dateformat; $archive_week_end_date_format = $dateformat; } $now = date('Y-m-d H:i:s', time() + $time_difference * 3600); if ('monthly' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts[$wp_id]} WHERE post_date < '{$now}' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); if ($show_post_count) { $text = ereg_replace('%MONTH', $month[zeroise($arcresult->month, 2)], $wp_month_format); $text = ereg_replace('%YEAR', sprintf("%d", $arcresult->year), $text); $after = " ({$arcresult->posts})"; } else { $text = ereg_replace('%MONTH', $month[zeroise($arcresult->month, 2)], $wp_month_format); $text = ereg_replace('%YEAR', sprintf("%d", $arcresult->year), $text); } echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('daily' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM {$wpdb->posts[$wp_id]} WHERE post_date < '{$now}' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth); $text = mysql2date($archive_day_date_format, $date); echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('weekly' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, " . get_settings('start_of_week') . ") AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM {$wpdb->posts[$wp_id]} WHERE post_date < '{$now}' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); $arc_w_last = ''; if ($arcresults) { foreach ($arcresults as $arcresult) { if ($arcresult->week != $arc_w_last) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend($arcresult->yyyymmdd, get_settings('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf("%s/index.php?m=%s&w=%d", $siteurl, $arc_year, $arcresult->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; echo get_archives_link($url, $text, $format, $before, $after); } } } } elseif ('postbypost' == $type) { $arcresults = $wpdb->get_results("SELECT ID, post_date, post_title FROM {$wpdb->posts[$wp_id]} WHERE post_date < '{$now}' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); if ($arcresults) { foreach ($arcresults as $arcresult) { if ($arcresult->post_date != '0000-00-00 00:00:00') { $url = get_permalink($arcresult->ID); $arc_title = stripslashes($arcresult->post_title); if ($arc_title) { $text = strip_tags($arc_title); } else { $text = $arcresult->ID; } echo get_archives_link($url, $text, $format, $before, $after); } } } } }
/** * Display archive links based on type and format. * * The 'type' argument offers a few choices and by default will display monthly * archive links. The other options for values are 'daily', 'weekly', 'monthly', * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the * same archive link list, the difference between the two is that 'alpha' * will order by post title and 'postbypost' will order by post date. * * The date archives will logically display dates with links to the archive post * page. The 'postbypost' and 'alpha' values for 'type' argument will display * the post titles. * * The 'limit' argument will only display a limited amount of links, specified * by the 'limit' integer value. By default, there is no limit. The * 'show_post_count' argument will show how many posts are within the archive. * By default, the 'show_post_count' argument is set to false. * * For the 'format', 'before', and 'after' arguments, see {@link * get_archives_link()}. The values of these arguments have to do with that * function. * * @since 1.2.0 * * @param string|array $args Optional. Override defaults. */ function wp_get_archives($args = '') { global $wpdb, $wp_locale; $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if ('' == $type) { $type = 'monthly'; } if ('' != $limit) { $limit = absint($limit); $limit = ' LIMIT ' . $limit; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } //filters $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r); $join = apply_filters('getarchives_join', '', $r); $output = ''; if ('monthly' == $type) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC {$limit}"; $key = md5($query); $cache = wp_cache_get('wp_get_archives', 'general'); if (!isset($cache[$key])) { $arcresults = $wpdb->get_results($query); $cache[$key] = $arcresults; wp_cache_set('wp_get_archives', $cache, 'general'); } else { $arcresults = $cache[$key]; } if ($arcresults) { $afterafter = $after; foreach ((array) $arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } $output .= get_archives_link($url, $text, $format, $before, $after); } } } elseif ('yearly' == $type) { $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date) ORDER BY post_date DESC {$limit}"; $key = md5($query); $cache = wp_cache_get('wp_get_archives', 'general'); if (!isset($cache[$key])) { $arcresults = $wpdb->get_results($query); $cache[$key] = $arcresults; wp_cache_set('wp_get_archives', $cache, 'general'); } else { $arcresults = $cache[$key]; } if ($arcresults) { $afterafter = $after; foreach ((array) $arcresults as $arcresult) { $url = get_year_link($arcresult->year); $text = sprintf('%d', $arcresult->year); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } $output .= get_archives_link($url, $text, $format, $before, $after); } } } elseif ('daily' == $type) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC {$limit}"; $key = md5($query); $cache = wp_cache_get('wp_get_archives', 'general'); if (!isset($cache[$key])) { $arcresults = $wpdb->get_results($query); $cache[$key] = $arcresults; wp_cache_set('wp_get_archives', $cache, 'general'); } else { $arcresults = $cache[$key]; } if ($arcresults) { $afterafter = $after; foreach ((array) $arcresults as $arcresult) { $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth); $text = mysql2date($archive_day_date_format, $date); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } $output .= get_archives_link($url, $text, $format, $before, $after); } } } elseif ('weekly' == $type) { $week = _wp_mysql_week('`post_date`'); $query = "SELECT DISTINCT {$week} AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `{$wpdb->posts}` {$join} {$where} GROUP BY {$week}, YEAR( `post_date` ) ORDER BY `post_date` DESC {$limit}"; $key = md5($query); $cache = wp_cache_get('wp_get_archives', 'general'); if (!isset($cache[$key])) { $arcresults = $wpdb->get_results($query); $cache[$key] = $arcresults; wp_cache_set('wp_get_archives', $cache, 'general'); } else { $arcresults = $cache[$key]; } $arc_w_last = ''; $afterafter = $after; if ($arcresults) { foreach ((array) $arcresults as $arcresult) { if ($arcresult->week != $arc_w_last) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $arcresult->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } $output .= get_archives_link($url, $text, $format, $before, $after); } } } } elseif ('postbypost' == $type || 'alpha' == $type) { $orderby = 'alpha' == $type ? 'post_title ASC ' : 'post_date DESC '; $query = "SELECT * FROM {$wpdb->posts} {$join} {$where} ORDER BY {$orderby} {$limit}"; $key = md5($query); $cache = wp_cache_get('wp_get_archives', 'general'); if (!isset($cache[$key])) { $arcresults = $wpdb->get_results($query); $cache[$key] = $arcresults; wp_cache_set('wp_get_archives', $cache, 'general'); } else { $arcresults = $cache[$key]; } if ($arcresults) { foreach ((array) $arcresults as $arcresult) { if ($arcresult->post_date != '0000-00-00 00:00:00') { $url = get_permalink($arcresult); if ($arcresult->post_title) { $text = strip_tags(apply_filters('the_title', $arcresult->post_title, $arcresult->ID)); } else { $text = $arcresult->ID; } $output .= get_archives_link($url, $text, $format, $before, $after); } } } } if ($echo) { echo $output; } else { return $output; } }
/** * Gets the items for the breadcrumb trail. This is the heart of the script. It checks the current page * being viewed and decided based on the information provided by WordPress what items should be * added to the breadcrumb trail. * * @since 0.4.0 * @todo Build in caching based on the queried object ID. * @access public * @param array $args Mixed arguments for the menu. * @return array List of items to be shown in the trail. */ function tc_breadcrumb_trail_get_items($args = array()) { global $wp_rewrite; /* Set up an empty trail array and empty path. */ $trail = array(); $path = ''; /* If $show_home is set and we're not on the front page of the site, link to the home page. */ if (!is_front_page() && $args['show_home']) { if (is_multisite() && true === $args['network']) { $trail[] = '<a href="' . network_home_url() . '">' . $args['show_home'] . '</a>'; $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . get_bloginfo('name') . '</a>'; } else { $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>'; } } /* If bbPress is installed and we're on a bbPress page. */ if (function_exists('is_bbpress') && is_bbpress()) { $trail = array_merge($trail, tc_breadcrumb_trail_get_bbpress_items()); } elseif (is_front_page()) { if (!is_paged() && $args['show_home'] && $args['front_page']) { if (is_multisite() && true === $args['network']) { $trail[] = '<a href="' . network_home_url() . '">' . $args['show_home'] . '</a>'; $trail[] = get_bloginfo('name'); } else { $trail[] = $args['show_home']; } } elseif (is_paged() && $args['show_home'] && $args['front_page']) { if (is_multisite() && true === $args['network']) { $trail[] = '<a href="' . network_home_url() . '">' . $args['show_home'] . '</a>'; $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . get_bloginfo('name') . '</a>'; } else { $trail[] = '<a href="' . esc_url(home_url()) . '" title="' . esc_attr(get_bloginfo('name')) . '" rel="home" class="trail-begin">' . $args['show_home'] . '</a>'; } } } elseif (is_home()) { $home_page = get_page(get_queried_object_id()); $trail = array_merge($trail, tc_breadcrumb_trail_get_parents($home_page->post_parent, '')); if (is_paged()) { $trail[] = '<a href="' . get_permalink($home_page->ID) . '" title="' . esc_attr(get_the_title($home_page->ID)) . '">' . get_the_title($home_page->ID) . '</a>'; } else { $trail[] = get_the_title($home_page->ID); } } elseif (is_singular()) { /* Get singular post variables needed. */ $post = get_queried_object(); $post_id = absint(get_queried_object_id()); $post_type = $post->post_type; $parent = absint($post->post_parent); /* Get the post type object. */ $post_type_object = get_post_type_object($post_type); /* If viewing a singular 'post'. */ if ('post' == $post_type) { /* If $front has been set, add it to the $path. */ $path .= trailingslashit($wp_rewrite->front); /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Map the permalink structure tags to actual links. */ $trail = array_merge($trail, tc_breadcrumb_trail_map_rewrite_tags($post_id, get_option('permalink_structure'), $args)); } elseif ('attachment' == $post_type) { /* Get the parent post ID. */ $parent_id = $post->post_parent; /* If the attachment has a parent (attached to a post). */ if (0 < $parent_id) { /* Get the parent post type. */ $parent_post_type = get_post_type($parent_id); /* If the post type is 'post'. */ if ('post' == $parent_post_type) { /* If $front has been set, add it to the $path. */ $path .= trailingslashit($wp_rewrite->front); /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Map the post (parent) permalink structure tags to actual links. */ $trail = array_merge($trail, tc_breadcrumb_trail_map_rewrite_tags($post->post_parent, get_option('permalink_structure'), $args)); } elseif ('page' !== $parent_post_type) { $parent_post_type_object = get_post_type_object($parent_post_type); /* If $front has been set, add it to the $path. */ if ($parent_post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($parent_post_type_object->rewrite['slug'])) { $path .= $parent_post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* If there's an archive page, add it to the trail. */ if (!empty($parent_post_type_object->has_archive)) { /* Add support for a non-standard label of 'archive_title' (special use case). */ $label = !empty($parent_post_type_object->labels->archive_title) ? $parent_post_type_object->labels->archive_title : $parent_post_type_object->labels->name; $trail[] = '<a href="' . get_post_type_archive_link($parent_post_type) . '" title="' . esc_attr($label) . '">' . $label . '</a>'; } } } } elseif ('page' !== $post_type) { /* If $front has been set, add it to the $path. */ if (isset($post_type_object) && $post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($post_type_object->rewrite['slug'])) { $path .= $post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* If there's an archive page, add it to the trail. */ if (!empty($post_type_object->has_archive)) { /* Add support for a non-standard label of 'archive_title' (special use case). */ $label = !empty($post_type_object->labels->archive_title) ? $post_type_object->labels->archive_title : $post_type_object->labels->name; $trail[] = '<a href="' . get_post_type_archive_link($post_type) . '" title="' . esc_attr($label) . '">' . $label . '</a>'; } } /* If the post type path returns nothing and there is a parent, get its parents. */ if (empty($path) && 0 !== $parent || 'attachment' == $post_type) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents($parent, '')); } elseif (0 !== $parent && is_post_type_hierarchical($post_type)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents($parent, '')); } /* Display terms for specific post type taxonomy if requested. */ if (!empty($args["singular_{$post_type}_taxonomy"]) && ($terms = get_the_term_list($post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', ''))) { $trail[] = $terms; } /* End with the post title. */ $post_title = single_post_title('', false); if (1 < get_query_var('page') && !empty($post_title)) { $trail[] = '<a href="' . get_permalink($post_id) . '" title="' . esc_attr($post_title) . '">' . $post_title . '</a>'; } elseif (!empty($post_title)) { $trail[] = $post_title; } } elseif (is_archive()) { /* If viewing a taxonomy term archive. */ if (is_tax() || is_category() || is_tag()) { /* Get some taxonomy and term variables. */ $term = get_queried_object(); $taxonomy = get_taxonomy($term->taxonomy); /* Get the path to the term archive. Use this to determine if a page is present with it. */ if (is_category()) { $path = get_option('category_base'); } elseif (is_tag()) { $path = get_option('tag_base'); } else { if ($taxonomy->rewrite['with_front'] && $wp_rewrite->front) { $path = trailingslashit($wp_rewrite->front); } $path .= $taxonomy->rewrite['slug']; } /* Get parent pages by path if they exist. */ if ($path) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'. */ if ($taxonomy->rewrite['slug']) { /* Get public post types that match the rewrite slug. */ $post_types = get_post_types(array('public' => true, 'has_archive' => $taxonomy->rewrite['slug']), 'objects'); /** * If any post types are found, loop through them to find one that matches. * The reason for this is because WP doesn't match the 'has_archive' string * exactly when calling get_post_types(). I'm assuming it just matches 'true'. */ if (!empty($post_types)) { foreach ($post_types as $post_type_object) { if ($taxonomy->rewrite['slug'] === $post_type_object->has_archive) { /* Add support for a non-standard label of 'archive_title' (special use case). */ $label = !empty($post_type_object->labels->archive_title) ? $post_type_object->labels->archive_title : $post_type_object->labels->name; /* Add the post type archive link to the trail. */ $trail[] = '<a href="' . get_post_type_archive_link($post_type_object->name) . '" title="' . esc_attr($label) . '">' . $label . '</a>'; /* Break out of the loop. */ break; } } } } /* If the taxonomy is hierarchical, list its parent terms. */ if (is_taxonomy_hierarchical($term->taxonomy) && $term->parent) { $trail = array_merge($trail, tc_breadcrumb_trail_get_term_parents($term->parent, $term->taxonomy)); } /* Add the term name to the trail end. */ if (is_paged()) { $trail[] = '<a href="' . esc_url(get_term_link($term, $term->taxonomy)) . '" title="' . esc_attr(single_term_title('', false)) . '">' . single_term_title('', false) . '</a>'; } else { $trail[] = single_term_title('', false); } } elseif (is_post_type_archive()) { /* Get the post type object. */ $post_type_object = get_post_type_object(get_query_var('post_type')); /* If $front has been set, add it to the $path. */ if ($post_type_object->rewrite['with_front'] && $wp_rewrite->front) { $path .= trailingslashit($wp_rewrite->front); } /* If there's a slug, add it to the $path. */ if (!empty($post_type_object->rewrite['slug'])) { $path .= $post_type_object->rewrite['slug']; } /* If there's a path, check for parents. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Add the post type [plural] name to the trail end. */ if (is_paged()) { $trail[] = '<a href="' . esc_url(get_post_type_archive_link($post_type_object->name)) . '" title="' . esc_attr(post_type_archive_title('', false)) . '">' . post_type_archive_title('', false) . '</a>'; } else { $trail[] = post_type_archive_title('', false); } } elseif (is_author()) { /* Get the user ID. */ $user_id = get_query_var('author'); /* If $front has been set, add it to $path. */ if (!empty($wp_rewrite->front)) { $path .= trailingslashit($wp_rewrite->front); } /* If an $author_base exists, add it to $path. */ if (!empty($wp_rewrite->author_base)) { $path .= $wp_rewrite->author_base; } /* If $path exists, check for parent pages. */ if (!empty($path)) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $path)); } /* Add the author's display name to the trail end. */ if (is_paged()) { $trail[] = '<a href="' . esc_url(get_author_posts_url($user_id)) . '" title="' . esc_attr(get_the_author_meta('display_name', $user_id)) . '">' . get_the_author_meta('display_name', $user_id) . '</a>'; } else { $trail[] = get_the_author_meta('display_name', $user_id); } } elseif (is_time()) { if (get_query_var('minute') && get_query_var('hour')) { $trail[] = get_the_time(__('g:i a', 'breadcrumb-trail')); } elseif (get_query_var('minute')) { $trail[] = sprintf(__('Minute %1$s', 'breadcrumb-trail'), get_the_time(__('i', 'breadcrumb-trail'))); } elseif (get_query_var('hour')) { $trail[] = get_the_time(__('g a', 'breadcrumb-trail')); } } elseif (is_date()) { /* If $front has been set, check for parent pages. */ if ($wp_rewrite->front) { $trail = array_merge($trail, tc_breadcrumb_trail_get_parents('', $wp_rewrite->front)); } if (is_day()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'breadcrumb-trail')) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'breadcrumb-trail')) . '">' . get_the_time(__('F', 'breadcrumb-trail')) . '</a>'; if (is_paged()) { $trail[] = '<a href="' . get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d')) . '" title="' . get_the_time(esc_attr__('d', 'breadcrumb-trail')) . '">' . get_the_time(__('d', 'breadcrumb-trail')) . '</a>'; } else { $trail[] = get_the_time(__('d', 'breadcrumb-trail')); } } elseif (get_query_var('w')) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'breadcrumb-trail')) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; if (is_paged()) { $trail[] = get_archives_link(add_query_arg(array('m' => get_the_time('Y'), 'w' => get_the_time('W')), esc_url(home_url())), sprintf(__('Week %1$s', 'breadcrumb-trail'), get_the_time(esc_attr__('W', 'breadcrumb-trail'))), false); } else { $trail[] = sprintf(__('Week %1$s', 'breadcrumb-trail'), get_the_time(esc_attr__('W', 'breadcrumb-trail'))); } } elseif (is_month()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . get_the_time(esc_attr__('Y', 'breadcrumb-trail')) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; if (is_paged()) { $trail[] = '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '" title="' . get_the_time(esc_attr__('F', 'breadcrumb-trail')) . '">' . get_the_time(__('F', 'breadcrumb-trail')) . '</a>'; } else { $trail[] = get_the_time(__('F', 'breadcrumb-trail')); } } elseif (is_year()) { if (is_paged()) { $trail[] = '<a href="' . get_year_link(get_the_time('Y')) . '" title="' . esc_attr(get_the_time(__('Y', 'breadcrumb-trail'))) . '">' . get_the_time(__('Y', 'breadcrumb-trail')) . '</a>'; } else { $trail[] = get_the_time(__('Y', 'breadcrumb-trail')); } } } } elseif (is_search()) { if (is_paged()) { $trail[] = '<a href="' . get_search_link() . '" title="' . sprintf(esc_attr__('Search results for "%1$s"', 'breadcrumb-trail'), esc_attr(get_search_query())) . '">' . sprintf(__('Search results for "%1$s"', 'breadcrumb-trail'), esc_attr(get_search_query())) . '</a>'; } else { $trail[] = sprintf(__('Search results for "%1$s"', 'breadcrumb-trail'), esc_attr(get_search_query())); } } elseif (is_404()) { $trail[] = __('404 Not Found', 'breadcrumb-trail'); } /* Check for pagination. */ if (is_paged()) { $trail[] = sprintf(__('Page %d', 'breadcrumb-trail'), absint(get_query_var('paged'))); } elseif (is_singular() && 1 < get_query_var('page')) { $trail[] = sprintf(__('Page %d', 'breadcrumb-trail'), absint(get_query_var('page'))); } /* Allow devs to step in and filter the $trail array. */ return apply_filters('breadcrumb_trail_items', $trail, $args); }
function echo_marchive($old_date, $format, $before, $count, $show_post_count) { global $persian_month_names; $year = substr($old_date, 0, 4); $month = substr($old_date, 4, 2); if ($show_post_count) { $count = ' (' . fixnumber($count) . ')'; } else { $count = ''; } echo get_archives_link(get_month_link($year, $month), $persian_month_names[intval($month)] . ' ' . fixnumber($year), $format, $before, $count); }
$items = ''; foreach ($archives as $archive) { // Build URL $url = ctc_post_type_get_month_link($archive->year, $archive->month, $instance['post_type']); // Format of link text /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(_x('%1$s %2$d', 'archives widget', 'uplifted'), $wp_locale->get_month($archive->month), $archive->year); // Show count after link? $after = ''; if (!empty($instance['show_count'])) { // show count $after = ' (' . $archive->posts . ')'; } // Month item $format = 'html'; // list link if (!empty($instance['show_dropdown'])) { $format = 'option'; // dropdown option } $items .= get_archives_link($url, $text, $format, '', $after); } // Show as dropdown if (!empty($instance['show_dropdown'])) { echo '<form>'; echo ' <select onchange="document.location.href=this.options[this.selectedIndex].value;">'; echo ' <option value="">' . _x('Select Month', 'archives widget', 'uplifted') . '</option>'; echo $items; echo ' </select>'; echo '</form>'; } else {
function wp_get_archives($args = '') { global $wp_locale, $wpdb; if (is_array($args)) { $r =& $args; } else { parse_str($args, $r); } $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false); $r = array_merge($defaults, $r); extract($r); if ('' == $type) { $type = 'monthly'; } if ('' != $limit) { $limit = (int) $limit; $limit = ' LIMIT ' . $limit; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } $add_hours = intval(get_option('gmt_offset')); $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours)); if ('monthly' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit); if ($arcresults) { $afterafter = $after; foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('yearly' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} WHERE post_type ='post' AND post_status = 'publish' GROUP BY YEAR(post_date) ORDER BY post_date DESC" . $limit); if ($arcresults) { $afterafter = $after; foreach ($arcresults as $arcresult) { $url = get_year_link($arcresult->year); $text = sprintf('%d', $arcresult->year); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('daily' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC" . $limit); if ($arcresults) { $afterafter = $after; foreach ($arcresults as $arcresult) { $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth); $text = mysql2date($archive_day_date_format, $date); if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('weekly' == $type) { $start_of_week = get_option('start_of_week'); $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, {$start_of_week}) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' GROUP BY WEEK(post_date, {$start_of_week}), YEAR(post_date) ORDER BY post_date DESC" . $limit); $arc_w_last = ''; $afterafter = $after; if ($arcresults) { foreach ($arcresults as $arcresult) { if ($arcresult->week != $arc_w_last) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ($show_post_count) { $after = ' (' . $arcresult->posts . ')' . $afterafter; } echo get_archives_link($url, $text, $format, $before, $after); } } } } elseif ('postbypost' == $type || 'alpha' == $type) { 'alpha' == $type ? $orderby = "post_title ASC " : ($orderby = "post_date DESC "); $arcresults = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' ORDER BY {$orderby} {$limit}"); if ($arcresults) { foreach ($arcresults as $arcresult) { if ($arcresult->post_date != '0000-00-00 00:00:00') { $url = get_permalink($arcresult); $arc_title = $arcresult->post_title; if ($arc_title) { $text = strip_tags($arc_title); } else { $text = $arcresult->ID; } echo get_archives_link($url, $text, $format, $before, $after); } } } } }
/** * function that extend the wp_get_archives * @see wp-includes/general-template.php * * @since 1.0.0 */ public function get_custom_post_type_archives($args = '') { global $wpdb, $wp_locale; $defaults = array('posttype' => 'post', 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC'); $r = wp_parse_args($args, $defaults); if ('' == $r['posttype']) { $r['posttype'] = 'post'; } $posttype = $r['posttype']; if ('' == $r['type']) { $r['type'] = 'monthly'; } if (!empty($r['limit'])) { $r['limit'] = absint($r['limit']); $r['limit'] = ' LIMIT ' . $r['limit']; } $order = strtoupper($r['order']); if ('ASC' !== $order) { $order = 'DESC'; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } /** * Filter the SQL WHERE clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_where Portion of SQL query containing the WHERE clause. * @param array $r An array of default arguments. */ $where = apply_filters('getarchives_where', "WHERE post_type = '{$posttype}' AND post_status = 'publish'", $r); /** * Filter the SQL JOIN clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_join Portion of SQL query containing JOIN clause. * @param array $r An array of default arguments. */ $join = apply_filters('getarchives_join', '', $r); $output = ''; $last_changed = wp_cache_get('last_changed', 'posts'); if (!$last_changed) { $last_changed = microtime(); wp_cache_set('last_changed', $last_changed, 'posts'); } $limit = $r['limit']; if ('monthly' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "get_custom_post_type_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = $this->get_custom_post_type_month_link($posttype, $result->year, $result->month); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%1$s %2$d', 'custom-post-type-widgets'), $wp_locale->get_month($result->month), $result->year); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } if ($r['echo']) { echo $output; } else { return $output; } }
function get_wpu_latest_blogposts($args = '') { global $wpuAbs, $wpdb; $defaults = array('limit' => '20', 'before' => '<li>', 'after' => '</li>'); extract(_wpu_process_args($args, $defaults)); if ('' != $limit) { $limit = (int) $limit; $limit_sql = ' LIMIT ' . $limit; } $orderby_sql = "post_date DESC "; $posts = $wpdb->get_results("SELECT ID, post_author, post_title FROM {$wpdb->posts} \n\t\tWHERE post_type = 'post' \n\t\tAND post_author <> 1\n\t\tAND post_status = 'publish' \n\t\tORDER BY {$orderby_sql} \n\t\t{$limit_sql}"); if ($posts) { $htmlOut = ''; foreach ($posts as $post) { $lastPostTitle = wpu_censor(strip_tags($post->post_title)); $blogTitle = wpu_censor(strip_tags(get_usermeta($post->post_author, 'blog_title'))); $blogTitle = $blogTitle == '' ? $wpuAbs->lang('default_blogname') : $blogTitle; $lastPostURL = get_permalink($post->ID); if (function_exists('get_author_posts_url')) { //WP >= 2.1 branch $blogPath = get_author_posts_url($post->post_author); } else { //deprecated branch $blogPath = get_author_link(false, $author->post_author); } $postLink = get_archives_link($lastPostURL, $lastPostTitle, '', $before, ''); $blogLink = get_archives_link($blogPath, $blogTitle, '', '', $after); $htmlOut .= sprintf(__('%s, in %s'), trim($postLink), $blogLink); } return $htmlOut; } }
function wp_get_archives($args = '') { global $wpdb, $wp_locale; $defaults = array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( '' == $type ) $type = 'monthly'; if ( '' != $limit ) { $limit = absint($limit); $limit = ' LIMIT '.$limit; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if ( !$archive_date_format_over_ride ) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } //filters $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); $join = apply_filters('getarchives_join', "", $r); if ( 'monthly' == $type ) { $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb->get_results($query); $cache[ $key ] = $arcresults; wp_cache_add( 'wp_get_archives', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ( $arcresults ) { $afterafter = $after; foreach ( $arcresults as $arcresult ) { $url = get_month_link($arcresult->year, $arcresult->month); $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); if ( $show_post_count ) $after = ' ('.$arcresult->posts.')' . $afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('yearly' == $type) { $query = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb->get_results($query); $cache[ $key ] = $arcresults; wp_cache_add( 'wp_get_archives', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ($arcresults) { $afterafter = $after; foreach ($arcresults as $arcresult) { $url = get_year_link($arcresult->year); $text = sprintf('%d', $arcresult->year); if ($show_post_count) $after = ' ('.$arcresult->posts.')' . $afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ( 'daily' == $type ) { $query = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb->get_results($query); $cache[ $key ] = $arcresults; wp_cache_add( 'wp_get_archives', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ( $arcresults ) { $afterafter = $after; foreach ( $arcresults as $arcresult ) { $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth); $text = mysql2date($archive_day_date_format, $date); if ($show_post_count) $after = ' ('.$arcresult->posts.')'.$afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ( 'weekly' == $type ) { $start_of_week = get_option('start_of_week'); $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb->get_results($query); $cache[ $key ] = $arcresults; wp_cache_add( 'wp_get_archives', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } $arc_w_last = ''; $afterafter = $after; if ( $arcresults ) { foreach ( $arcresults as $arcresult ) { if ( $arcresult->week != $arc_w_last ) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ($show_post_count) $after = ' ('.$arcresult->posts.')'.$afterafter; echo get_archives_link($url, $text, $format, $before, $after); } } } } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) { ('alpha' == $type) ? $orderby = "post_title ASC " : $orderby = "post_date DESC "; $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { $arcresults = $wpdb->get_results($query); $cache[ $key ] = $arcresults; wp_cache_add( 'wp_get_archives', $cache, 'general' ); } else { $arcresults = $cache[ $key ]; } if ( $arcresults ) { foreach ( $arcresults as $arcresult ) { if ( $arcresult->post_date != '0000-00-00 00:00:00' ) { $url = get_permalink($arcresult); $arc_title = $arcresult->post_title; if ( $arc_title ) $text = strip_tags(apply_filters('the_title', $arc_title)); else $text = $arcresult->ID; echo get_archives_link($url, $text, $format, $before, $after); } } } } }
function get_archives($type='', $limit='', $format='html', $before = '', $after = '', $show_post_count = false) { global $month, $wpdb; if ('' == $type) { $type = 'monthly'; } if ('' != $limit) { $limit = (int) $limit; $limit = ' LIMIT '.$limit; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_settings('date_format'); $archive_week_start_date_format = get_settings('date_format'); $archive_week_end_date_format = get_settings('date_format'); } $add_hours = intval(get_settings('gmt_offset')); $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours)); $now = current_time('mysql'); if ('monthly' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit); if ($arcresults) { $afterafter = $after; foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); if ($show_post_count) { $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year); $after = ' ('.$arcresult->posts.')' . $afterafter; } else { $text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year); } echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('daily' == $type) { $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth); $text = mysql2date($archive_day_date_format, $date); echo get_archives_link($url, $text, $format, $before, $after); } } } elseif ('weekly' == $type) { $start_of_week = get_settings('start_of_week'); $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); $arc_w_last = ''; if ($arcresults) { foreach ($arcresults as $arcresult) { if ($arcresult->week != $arc_w_last) { $arc_year = $arcresult->yr; $arc_w_last = $arcresult->week; $arc_week = get_weekstartend($arcresult->yyyymmdd, get_settings('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%s/%s%sm%s%s%sw%s%d', get_settings('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; echo get_archives_link($url, $text, $format, $before, $after); } } } } elseif ('postbypost' == $type) { $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); if ($arcresults) { foreach ($arcresults as $arcresult) { if ($arcresult->post_date != '0000-00-00 00:00:00') { $url = get_permalink($arcresult); $arc_title = $arcresult->post_title; if ($arc_title) { $text = strip_tags($arc_title); } else { $text = $arcresult->ID; } echo get_archives_link($url, $text, $format, $before, $after); } } } } }
/** * Display archive links grouped by year using CSS-based collapsing (based on wp_get_archives). * * @param string|array $args { * Default archive links arguments. Optional. * * @type bool $show_post_count Whether to display the post count alongside the link. Default false. * @type bool $use_triangles Whether to use triangles to indicate expansion instead of +/-. Default false. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. * Default 'DESC'. * } * @return string */ function collapsed_archives_get_collapsed_archives($args = '') { global $wpdb, $wp_locale; $defaults = array('show_post_count' => false, 'use_triangles' => false, 'order' => 'DESC'); $r = wp_parse_args($args, $defaults); $order = strtoupper($r['order']); if ($order !== 'ASC') { $order = 'DESC'; } $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r); $join = apply_filters('getarchives_join', '', $r); $output = ''; $last_changed = wp_cache_get('last_changed', 'posts'); if (!$last_changed) { $last_changed = microtime(); wp_cache_set('last_changed', $last_changed, 'posts'); } $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date {$order}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $output .= '<div class="collapsed-archives'; if ($r['use_triangles']) { $output .= ' collapsed-archives-triangles'; } $output .= '"><ul>'; $prev_year = false; foreach ((array) $results as $result) { if ($prev_year != $result->year) { if ($prev_year !== false) { $output .= '</ul></li>'; } $year_id = 'archive-year-' . $result->year; $output .= '<li>'; $output .= '<input type="checkbox" id="' . $year_id . '"'; if ($result->year == get_the_date('Y') && !is_page() || is_page() && $result->year == date('Y')) { $output .= ' checked'; } $output .= '>'; $output .= '<label for="' . $year_id . '"></label>'; $url = get_year_link($result->year); $after = ''; if ($r['show_post_count']) { $year_query = new WP_Query('year=' . $result->year); $after = ' (' . $year_query->found_posts . ')'; } $output .= get_archives_link($url, $result->year, '', '', $after); $output .= '<ul>'; $prev_year = $result->year; } $url = get_month_link($result->year, $result->month); /* translators: 1: month name */ $text = sprintf(__('%1$s'), $wp_locale->get_month($result->month)); $after = ''; if ($r['show_post_count']) { $after = ' (' . $result->posts . ')'; } $output .= get_archives_link($url, $text, 'html', '', $after); } } $output .= '</ul></li></ul></div>'; return $output; }
/** * @param array|string $args * @return array|string */ function get_items($args = null) { global $wpdb; $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'order' => 'DESC', 'post_type' => 'post', 'nested' => true); $r = wp_parse_args($args, $defaults); $type = $limit = $order = $post_type = $nested = $format = $before = $after = null; extract($r, EXTR_SKIP); if (empty($order)) { $order = 'DESC'; } if (empty($post_type)) { $post_type = 'post'; } if (empty($type)) { $type = 'monthly'; } if (!empty($limit)) { $limit = absint($limit); $limit = ' LIMIT ' . $limit; } $order = strtoupper($order); if ($order !== 'ASC') { $order = 'DESC'; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } $where = apply_filters('getarchives_where', 'WHERE post_type = "' . $post_type . '" AND post_status = "publish"', $r); $join = apply_filters('getarchives_join', '', $r); $output = array(); $last_changed = wp_cache_get('last_changed', 'posts'); if (!$last_changed) { $last_changed = microtime(); wp_cache_set('last_changed', $last_changed, 'posts'); } if ('monthly' == $type) { $output = $this->get_items_montly($args, $last_changed, $join, $where, $order, $limit, $nested); } elseif ('yearly' == $type) { $output = $this->get_items_yearly($args, $last_changed, $join, $where, $order, $limit); } elseif ('yearlymonthly' == $type || 'yearmonth' == $type) { $years = $this->get_items_yearly($args, $last_changed, $join, $where, $order, $limit); foreach ($years as &$year) { $args = array('show_year' => false); $year['children'] = $this->get_items_montly($args, $last_changed, $join, $where, $order, $limit); } $output = $years; } elseif ('daily' == $type) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); $cache[$key] = $results; wp_cache_set($key, $results, 'posts'); } if ($results) { foreach ((array) $results as $result) { $url = get_day_link($result->year, $result->month, $result->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth); $text = mysql2date($archive_day_date_format, $date); $output[] = $this->get_archives_link($url, $text); } } } elseif ('weekly' == $type) { $week = _wp_mysql_week('`post_date`'); $query = "SELECT DISTINCT {$week} AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, " . "count( `ID` ) AS `posts` FROM `{$wpdb->posts}` {$join} {$where} GROUP BY {$week}, YEAR( `post_date` ) ORDER BY `post_date` {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } $arc_w_last = ''; if ($results) { foreach ((array) $results as $result) { if ($result->week != $arc_w_last) { $arc_year = $result->yr; $arc_w_last = $result->week; $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; $output[] = $this->get_archives_link($url, $text); } } } } elseif ('postbypost' == $type || 'alpha' == $type) { $orderby = 'alpha' == $type ? 'post_title ASC ' : 'post_date DESC '; $query = "SELECT * FROM {$wpdb->posts} {$join} {$where} ORDER BY {$orderby} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { foreach ((array) $results as $result) { if ($result->post_date != '0000-00-00 00:00:00') { $url = get_permalink($result); if ($result->post_title) { /** This filter is documented in wp-includes/post-template.php */ $text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID)); } else { $text = $result->ID; } $output .= get_archives_link($url, $text, $format, $before, $after); } } } } return $output; }
/** * Get the archives wih custom format where it will print post * based on years while it able to show a month with empty posts. * * @todo memindahkan seluruh pembuatan perintah sql ke dalam method yg terpisah * * @global <type> $wpdb * @global <type> $wp_locale * @param boolean $echo print the output * @return mixed */ public function get_YearsLinkArchives($echo = TRUE) { global $wpdb, $wp_locale; $where = "WHERE post_type = 'post' AND post_status = 'publish' "; $join = ''; $limit = ''; if ('monthly' == $this->get_type()) { /** * get distinct years */ $query = "SELECT DISTINCT YEAR(post_date) AS `year` FROM {$wpdb->posts}\n {$where}\n GROUP BY YEAR(post_date)\n ORDER BY post_date ASC\n {$limit}"; $yearresults = $wpdb->get_results($query); $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts\n FROM {$wpdb->posts}\n {$join}\n {$where}\n GROUP BY YEAR(post_date), MONTH(post_date)\n ORDER BY post_date ASC\n {$limit}"; $arcresults = $wpdb->get_results($query); /** * processeing * @todo : menambah properties standar bagi class ini seperti $after, $before, $format * @todo : algoritma darurat ini sebaiknya diganti dengan metode yg rapi dan * tidak membingungkan */ $format = 'custom'; $before = ' ['; $after = '] '; foreach ($yearresults as $years) { $url = get_year_link($years->year); $text = sprintf('%d', $years->year); $before = '<div class="year">'; $after = '</div>'; $output = get_archives_link($url, $text, $format, $before, $after); $month_number = 0; foreach ($arcresults as $arcresult) { if ($month_number >= 13) { $month_number = 0; } if ($years->year == $arcresult->year) { $month_number++; /*** * try to print all month event those who doesn't have post in it * $last_haspost_month bertugas sbg penanda bagi * operasi CONDITIONAL Ke-2 (below) */ $last_haspost_month = $arcresult->month; while ($month_number < 13 && $month_number < $last_haspost_month) { $before = '<div class="nopost">'; $after = '</div>'; $text = sprintf(__('%1$s'), $wp_locale->get_month($month_number)); $output .= "\t{$before} {$text} {$after}\n"; $month_number++; } $before = '<div class="haspost">'; $after = '</div>'; $url = get_month_link($arcresult->year, $arcresult->month) . '/'; $text = sprintf(__('%1$s'), $wp_locale->get_month($arcresult->month)); $output .= get_archives_link($url, $text, $format, $before, $after); } else { /** * CONDITIONAL Ke-2 * * Reverting last year's month that consist posts. then ileterate into * tha last possible months (bulan ke-12) */ while ($last_haspost_month < 13) { $last_haspost_month++; $before = '<div class="nopost">'; $after = '</div>'; $text = sprintf(__('%1$s'), $wp_locale->get_month($last_haspost_month)); $output .= "\t{$before} {$text} {$after}\n"; } continue; } } $beforeyear = '<li>'; $afteryear = '</li>'; /*** * adding xhtml after year/before years where the latest post will be * in highest ladders */ $last_output = $beforeyear . $output . $afteryear . $last_output; } } if ($this->get_echo() == TRUE) { echo $last_output; } else { return $last_output; } }
/** * Adds the items to the trail items array for week archives. * * @since 1.0.0 * @access protected * @return void */ protected function add_week_archive_items() { // Add $wp_rewrite->front to the trail. $this->add_rewrite_front_items(); // Get the year and week. $year = sprintf($this->labels['archive_year'], get_the_time(esc_html_x('Y', 'yearly archives date format', 'simple-life'))); $week = sprintf($this->labels['archive_week'], get_the_time(esc_html_x('W', 'weekly archives date format', 'simple-life'))); // Add the year item. $this->items[] = sprintf('<a href="%s">%s</a>', esc_url(get_year_link(get_the_time('Y'))), $year); // Add the week item. if (is_paged()) { $this->items[] = esc_url(get_archives_link(add_query_arg(array('m' => get_the_time('Y'), 'w' => get_the_time('W')), home_url()), $week, false)); } elseif (true === $this->args['show_title']) { $this->items[] = $week; } }
/** * own widget function */ function ztjalali_archive_widget($type = 'monthly', $format = 'html', $show_post_count = false, $limit = 12, $before = '', $after = '') { global $wpdb, $jdate_month_name, $ztjalali_option; if ($type === "yearly") { $YearlyQry = $wpdb->get_results("SELECT DATE_FORMAT( post_date ,'%Y-%m-%d' ) as date,\n count(ID) as count,\n YEAR(post_date) AS `year`, \n MONTH(post_date) AS `month`, \n DAYOFMONTH(post_date) AS `dayofmonth` \n FROM {$wpdb->posts} \n WHERE post_date < NOW() \n AND post_type = 'post' \n AND post_status = 'publish' \n GROUP BY date ORDER BY post_date DESC"); if (!empty($YearlyQry)) { $jYears = array(); $i = 1; foreach ($YearlyQry as $res) { $jalali_year = gregorian_to_jalali($res->year, $res->month, $res->dayofmonth); $jYears[$jalali_year[0]]['year'] = $res->year; if (!array_key_exists('count', $jYears[$jalali_year[0]])) { $jYears[$jalali_year[0]]['count'] = 0; } $jYears[$jalali_year[0]]['count'] += $res->count; } foreach ($jYears as $jYear => $data) { if ($ztjalali_option['change_url_date_to_jalali']) { $url = get_year_link($jYear); } else { $url = get_year_link($data['year']); } $jYear = ztjalali_persian_num($jYear); $c_after = $show_post_count ? ' (' . ztjalali_persian_num($data['count']) . ')' . $after : ''; echo get_archives_link($url, $jYear, $format, $before, $c_after); if ($i == $limit) { break; } $i++; } } } elseif ("monthly" == $type or empty($type)) { $MonthlyQry = $wpdb->get_results("SELECT DATE_FORMAT( post_date ,'%Y-%m-%d' ) as date,\n count(ID) as count,\n YEAR(post_date) AS `year`, \n MONTH(post_date) AS `month`, \n DAYOFMONTH(post_date) AS `dayofmonth` \n FROM {$wpdb->posts} \n WHERE post_date < NOW() \n AND post_type = 'post' \n AND post_status = 'publish' \n GROUP BY date ORDER BY post_date DESC"); if (!empty($MonthlyQry)) { $jMonths = array(); foreach ($MonthlyQry as $res) { $jalali_month = gregorian_to_jalali($res->year, $res->month, $res->dayofmonth); $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['year'] = $res->year; $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['month'] = $res->month; if (!array_key_exists('count', $jMonths[$jalali_month[0] . '-' . $jalali_month[1]])) { $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['count'] = 0; } $jMonths[$jalali_month[0] . '-' . $jalali_month[1]]['count'] += $res->count; } $i = 1; foreach ($jMonths as $jMonth => $data) { list($jY, $jM) = explode('-', $jMonth); if ($ztjalali_option['change_url_date_to_jalali']) { $url = get_month_link($jY, $jM); } else { $url = get_month_link($data['year'], $data['month']); } $jY = ztjalali_persian_num($jY); $jM = $jdate_month_name[$jM]; $c_after = $show_post_count ? ' (' . ztjalali_persian_num($data['count']) . ')' . $after : ''; echo get_archives_link($url, $jM . ' ' . $jY, $format, $before, $c_after); if ($i == $limit) { break; } $i++; } } } elseif ("daily" == $type) { $limStr = ''; if (!empty($limit)) { $limit = (int) $limit; $limStr = ' LIMIT ' . $limit; } $DailyQry = $wpdb->get_results("SELECT DATE_FORMAT( post_date ,'%Y-%m-%d' ) as date,\n count(ID) as count,\n YEAR(post_date) AS `year`, \n MONTH(post_date) AS `month`, \n DAYOFMONTH(post_date) AS `dayofmonth` \n FROM {$wpdb->posts} \n WHERE post_date < NOW() \n AND post_type = 'post' \n AND post_status = 'publish' \n GROUP BY date ORDER BY post_date DESC " . $limStr); if (!empty($DailyQry)) { foreach ($DailyQry as $Daily) { list($jY, $jM, $jD) = gregorian_to_jalali($Daily->year, $Daily->month, $Daily->dayofmonth); if ($ztjalali_option['change_url_date_to_jalali']) { $url = get_day_link($jY, $jM, $jD); } else { $url = get_day_link($Daily->year, $Daily->month, $Daily->dayofmonth); } $date = mktime(0, 0, 0, $Daily->month, $Daily->dayofmonth, $Daily->year); $text = jdate(get_option('date_format'), $date); if ($show_post_count) { $c_after = ' (' . ztjalali_persian_num($Daily->count) . ')' . $after; } echo get_archives_link($url, $text, $format, $before, $c_after); } } } elseif ('postbypost' == $type) { $limStr = ''; if (!empty($limit)) { $limit = (int) $limit; $limStr = ' LIMIT ' . $limit; } $byPosts = $wpdb->get_results("SELECT ID, post_date, post_title FROM {$wpdb->posts} WHERE post_type='post' AND post_date < NOW() AND post_status = 'publish' ORDER BY post_date DESC" . $limStr); if (!empty($byPosts)) { foreach ($byPosts as $aPost) { if ($aPost->post_date != '0000-00-00 00:00:00') { $url = get_permalink($aPost->ID); echo get_archives_link($url, strip_tags($aPost->post_title), $format, $before, $after); } } } } }
/** * Display archive links based on type and format. * * @since 1.2.0 * * @see get_archives_link() * * @global wpdb $wpdb * @global WP_Locale $wp_locale * * @param string|array $args { * Default archive links arguments. Optional. * * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly', * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha' * display the same archive link list as well as post titles instead * of displaying dates. The difference between the two is that 'alpha' * will order by post title and 'postbypost' will order by post date. * Default 'monthly'. * @type string|int $limit Number of links to limit the query to. Default empty (no limit). * @type string $format Format each link should take using the $before and $after args. * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html' * (`<li>` tag), or a custom format, which generates a link anchor * with $before preceding and $after succeeding. Default 'html'. * @type string $before Markup to prepend to the beginning of each link. Default empty. * @type string $after Markup to append to the end of each link. Default empty. * @type bool $show_post_count Whether to display the post count alongside the link. Default false. * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo. * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. * Default 'DESC'. * } * @return string|void String when retrieving. */ function wp_get_archives($args = '') { global $wpdb, $wp_locale; $defaults = array('type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, 'echo' => 1, 'order' => 'DESC'); $r = wp_parse_args($args, $defaults); if ('' == $r['type']) { $r['type'] = 'monthly'; } if (!empty($r['limit'])) { $r['limit'] = absint($r['limit']); $r['limit'] = ' LIMIT ' . $r['limit']; } $order = strtoupper($r['order']); if ($order !== 'ASC') { $order = 'DESC'; } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = get_option('date_format'); $archive_week_start_date_format = get_option('date_format'); $archive_week_end_date_format = get_option('date_format'); } /** * Filter the SQL WHERE clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_where Portion of SQL query containing the WHERE clause. * @param array $r An array of default arguments. */ $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r); /** * Filter the SQL JOIN clause for retrieving archives. * * @since 2.2.0 * * @param string $sql_join Portion of SQL query containing JOIN clause. * @param array $r An array of default arguments. */ $join = apply_filters('getarchives_join', '', $r); $output = ''; $last_changed = wp_cache_get('last_changed', 'posts'); if (!$last_changed) { $last_changed = microtime(); wp_cache_set('last_changed', $last_changed, 'posts'); } $limit = $r['limit']; if ('monthly' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = get_month_link($result->year, $result->month); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } elseif ('yearly' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = get_year_link($result->year); $text = sprintf('%d', $result->year); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } elseif ('daily' == $r['type']) { $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { $after = $r['after']; foreach ((array) $results as $result) { $url = get_day_link($result->year, $result->month, $result->dayofmonth); $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth); $text = mysql2date($archive_day_date_format, $date); if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } elseif ('weekly' == $r['type']) { $week = _wp_mysql_week('`post_date`'); $query = "SELECT DISTINCT {$week} AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `{$wpdb->posts}` {$join} {$where} GROUP BY {$week}, YEAR( `post_date` ) ORDER BY `post_date` {$order} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } $arc_w_last = ''; if ($results) { $after = $r['after']; foreach ((array) $results as $result) { if ($result->week != $arc_w_last) { $arc_year = $result->yr; $arc_w_last = $result->week; $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ($r['show_post_count']) { $r['after'] = ' (' . $result->posts . ')' . $after; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } } elseif ('postbypost' == $r['type'] || 'alpha' == $r['type']) { $orderby = 'alpha' == $r['type'] ? 'post_title ASC ' : 'post_date DESC, ID DESC '; $query = "SELECT * FROM {$wpdb->posts} {$join} {$where} ORDER BY {$orderby} {$limit}"; $key = md5($query); $key = "wp_get_archives:{$key}:{$last_changed}"; if (!($results = wp_cache_get($key, 'posts'))) { $results = $wpdb->get_results($query); wp_cache_set($key, $results, 'posts'); } if ($results) { foreach ((array) $results as $result) { if ($result->post_date != '0000-00-00 00:00:00') { $url = get_permalink($result); if ($result->post_title) { /** This filter is documented in wp-includes/post-template.php */ $text = strip_tags(apply_filters('the_title', $result->post_title, $result->ID)); } else { $text = $result->ID; } $output .= get_archives_link($url, $text, $r['format'], $r['before'], $r['after']); } } } } if ($r['echo']) { echo $output; } else { return $output; } }
function get_archives($type = '', $limit = '', $format = 'html', $before = "", $after = "", $show_post_count = false, $selvalue = '', $echo = true) { $get_archives = ''; if (!$type) { $type = get_settings('archive_mode'); } // this is what will separate dates on weekly archive links $archive_week_separator = '–'; // archive link url $archive_link_m = wp_siteurl() . '/index.php?m='; # monthly archive; $archive_link_w = wp_siteurl() . '/index.php?w='; # weekly archive; $archive_link_p = wp_siteurl() . '/index.php?p='; # post-by-post archive; // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride $archive_date_format_over_ride = 0; // options for daily archive (only if you over-ride the general date format) $archive_day_date_format = 'Y/m/d'; // options for weekly archive (only if you over-ride the general date format) $archive_week_start_date_format = 'Y/m/d'; $archive_week_end_date_format = 'Y/m/d'; if (!$archive_date_format_over_ride) { $archive_day_date_format = $GLOBALS['dateformat']; $archive_week_start_date_format = $GLOBALS['dateformat']; $archive_week_end_date_format = $GLOBALS['dateformat']; } $now = current_time('mysql'); $postHandler =& wp_handler('Post'); if ('monthly' == $type) { $criteria =& new CriteriaCompo(new Criteria('post_date', $now, '<')); $criteria->add(new Criteria('post_status', 'publish')); $criteria->setSort('post_date'); $criteria->setOrder('DESC'); $criteria->setGroupby('YEAR(post_date), MONTH(post_date)'); if ($limit) { $criteria->setLimit($limit); } $postObjects =& $postHandler->getObjects($criteria, false, 'DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts'); if ($postObjects) { foreach ($postObjects as $postObject) { $this_year = $postObject->getExtraVar('year'); $this_month = $postObject->getExtraVar('month'); $url = get_month_link($this_year, $this_month); if ($show_post_count) { $text = format_month(sprintf("%d", $this_year), $GLOBALS['month'][zeroise($this_month, 2)]); $after = " (" . $postObject->getExtraVar('posts') . ")"; } else { $text = format_month(sprintf("%d", $this_year), $GLOBALS['month'][zeroise($this_month, 2)]); } $selected = $selvalue == $this_year . zeroise($this_month, 2); $get_archives .= get_archives_link($url, $text, $format, $before, $after, $selected); } } } elseif ('daily' == $type) { $criteria =& new CriteriaCompo(new Criteria('post_date', $now, '<')); $criteria->add(new Criteria('post_status', 'publish')); $criteria->setSort('post_date'); $criteria->setOrder('DESC'); if ($limit) { $criteria->setLimit($limit); } $postObjects =& $postHandler->getObjects($criteria, false, 'DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`'); if ($postObjects) { foreach ($postObjects as $postObject) { $this_year = $postObject->getExtraVar('year'); $this_month = $postObject->getExtraVar('month'); $this_day = $postObject->getExtraVar('dayofmonth'); $url = get_day_link($this_year, $this_month, $this_day); $date = sprintf("%d-%02d-%02d 00:00:00", $this_year, $this_month, $this_day); $text = mysql2date($archive_day_date_format, $date); $get_archives .= get_archives_link($url, $text, $format, $before, $after); } } } elseif ('weekly' == $type) { $criteria =& new CriteriaCompo(new Criteria('post_date', $now, '<')); $criteria->add(new Criteria('post_status', 'publish')); $criteria->setSort('post_date'); $criteria->setOrder('DESC'); if ($limit) { $criteria->setLimit($limit); } $postObjects =& $postHandler->getObjects($criteria, false, "DISTINCT WEEK(post_date, " . get_settings('start_of_week') . ") AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd"); $arc_w_last = ''; if ($postObjects) { foreach ($postObjects as $postObject) { $arc_week = $postObject->getExtraVar('week'); $arc_year = $postObject->getExtraVar('yr'); $arc_date = $postObject->getExtraVar('yyyymmdd'); if ($arc_week != $arc_w_last) { $arc_w_last = $arc_week; $arc_week_days = get_weekstartend($arc_date, get_settings('start_of_week')); $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week_days['start']); $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week_days['end']); $url = sprintf("%s/index.php?m=%s&w=%d", wp_siteurl(), $arc_year, $arc_week); $text = $arc_week_start . $archive_week_separator . $arc_week_end; $get_archives .= get_archives_link($url, $text, $format, $before, $after); } } } } elseif ('postbypost' == $type) { $criteria =& new CriteriaCompo(new Criteria('post_date', $now, '<')); $criteria->add(new Criteria('post_status', 'publish')); $criteria->setSort('post_date'); $criteria->setOrder('DESC'); if ($limit) { $criteria->setLimit($limit); } $postObjects =& $postHandler->getObjects($criteria, false, 'ID, post_date, post_title'); if ($postObjects) { foreach ($postObjects as $postObject) { if ($postObject->getVar('post_date') != '0000-00-00 00:00:00') { $url = get_permalink($postObject->getVar('ID')); $arc_title = $postObject->getVar('post_title'); if ($arc_title) { $text = strip_tags($arc_title); } else { $text = _WP_POST_NOTITLE; } $get_archives .= get_archives_link($url, $text, $format, $before, $after); } } } } return _echo($get_archives, $echo); }
/** * Adds the items to the trail items array for week archives. * * @since 0.6.0 * @access public * @return void */ public function do_week_archive_items() { /* Add $wp_rewrite->front to the trail. */ $this->do_rewrite_front_items(); /* Get the year and week. */ $year = sprintf($this->args['labels']['archive_year'], get_the_time(_x('Y', 'yearly archives date format', 'toivo-lite'))); $week = sprintf($this->args['labels']['archive_week'], get_the_time(_x('W', 'weekly archives date format', 'toivo-lite'))); /* Add the year item. */ $this->items[] = '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . $year . '</a>'; /* Add the week item. */ if (is_paged()) { $this->items[] = esc_url(get_archives_link(add_query_arg(array('m' => get_the_time('Y'), 'w' => get_the_time('W')), home_url()), $week, false)); } elseif (true === $this->args['show_title']) { $this->items[] = $week; } }
function widget($args, $instance) { global $wpdb, $wp_locale, $wp_query; $where = " where post_type = 'post' AND post_status = 'publish'"; $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM {$wpdb->posts} {$join} {$where} GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"; $results = $wpdb->get_results($query); $cYear = !empty($wp_query->query_vars['year']) ? $wp_query->query_vars['year'] : 0; $cMonth = !empty($wp_query->query_vars['monthnum']) ? $wp_query->query_vars['monthnum'] : 0; ?> <div class="widget widget_archive"> <h3><?php echo empty($instance['title']) ? __('Archives', 'woocommerce') : $instance['title']; ?> </h3> <ul class="archive"> <?php foreach ((array) $results as $result) { $url = get_month_link($result->year, $result->month); /* translators: 1: month name, 2: 4-digit year */ $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year); $output = get_archives_link($url, $text, $format, $before, $after); ?> <?php if ($cYear == $result->year && $cMonth == $result->month) { ?> <li class="current"><?php echo $output; ?> <ul> <?php query_posts("year={$cYear}&monthnum={$cMonth}"); if (have_posts()) { while (have_posts()) { the_post(); $count++; ?> <li><a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> "><?php the_title(); ?> </a></li> <?php } } ?> </ul> </li> <?php } else { ?> <li class=""><?php echo $output; ?> </li> <?php } } ?> </ul> </div> <?php }