Year and Month in Wordpress Archive List - php

I'd like to list all years from which there are public Wordpress posts, and in a sub-menu below, the months from those years. Example:
2016
August
March
2015
June
May
February
I have a working version of this inside a loop, but it requires me to manually add a new list every year. Is there any way to adjust it, so that it includes the new year automatically?
<h1>2016</h1>
<ul>
<?php
$string = wp_get_archives('type=monthly&year=2016&echo=0');
$pattern = ' ((19|20)\d{2}(</a>))';
echo preg_replace($pattern, '\\3', $string); '<li></li>';?>
</ul></a>
<h1>2015</h1>
<?php
$string = wp_get_archives('type=monthly&year=2015&echo=0');
$pattern = ' ((19|20)\d{2}(</a>))';
echo preg_replace($pattern, '\\3', $string); '<li></li>';?>
</ul></a>

Ok, found a very helpful post on stack exchange: here
Basically, add this to functions.php:
//List archives by year, then month
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 );
$year_url = get_year_link($arcresult->year);
/* translators: 1: month name, 2: 4-digit year */
$text = sprintf(__('%s'), $wp_locale->get_month($arcresult->month));
$year_text = sprintf('%d', $arcresult->year);
if ( $show_post_count )
$after = ' ('.$arcresult->posts.')' . $afterafter;
$year_output = get_archives_link($year_url, $year_text, $format, $before, $after);
$output .= ( $arcresult->year != $temp_year ) ? $year_output : '';
$output .= get_archives_link($url, $text, $format, $before, $after);
$temp_year = $arcresult->year;
}
}
$output .= '</ul>';
if ( $echo )
echo $output;
else
return $output;
}
And then call this function on the page:
<?php wp_custom_archive(); ?>
It will return a list exactly as needed, by year then month, with links to each!

<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
</select>

I would do it this way.
It's a bit shorter and easier to understand, and it relies on WP core functions, which is usually the preferable way to handle the data in WP. Also, it doesn't need expensive regex functions.
1. Add "in_year" option to the wp_get_archives() function
<?php
add_filter( 'getarchives_where', 'archives_in_specific_year', 10, 2 );
function archives_in_specific_year( $sql_where, $parsed_args ) {
if ( ! empty( $parsed_args['in_year'] ) ) {
$year = absint( $parsed_args['in_year'] );
$sql_where .= " AND YEAR(post_date) = $year";
}
return $sql_where;
}
?>
2. For each year, render that year and its months
<?php
$args = [
'type' => 'yearly',
'echo' => false,
];
$years = wp_get_archives( $args );
$years_array = explode( "\t", trim( wp_strip_all_tags( $years ) ) );
foreach ( $years_array as $current_year ) {
$current_year = intval( $current_year );
$monthly_args = [
'type' => 'monthly',
'format' => 'custom',
'echo' => false,
'before' => '<span>',
'after' => '</span>',
'in_year' => $current_year,
];
$months = str_replace( ' ' . $current_year, '', wp_get_archives( $monthly_args ) );
$yearly_args = [
'type' => 'yearly',
'after' => '<div>' . $months . '</div>',
'in_year' => $current_year,
];
wp_get_archives( $yearly_args );
}
?>

here's a simple mysql query, solved a similiar problem.
$query = 'SELECT DISTINCT MONTH(`post_date`) AS `month`, YEAR(`post_date`) AS `year` FROM `wp_posts` ORDER BY `post_date` ASC';
$results = $wpdb->get_results($query);

Related

WooCommerce checkout select field: Insert a key/value before calculated options array

I am working on my WordPress / Woocommerce website.
How can I add a constant value, which would always be the first value in the drop down list which consists of times (hour:minute). This constant value at the top should say "As soon as possible".
Here is the code which generates the form itself:
public function time_select( $checkout ) {
echo '<div id="local-pickup-time-select"><h2>' . __( 'Delivery Time', $this->plugin_slug ) . '</h2>';
woocommerce_form_field( 'local_pickup_time_select', array(
'type' => 'select',
'class' => array( 'local-pickup-time-select-field form-row-wide' ),
'label' => __( 'Delivery Time', $this->plugin_slug ),
'required' => true,
'options' => self::create_hour_options()
), $checkout->get_value( 'local_pickup_time_select' ));
self::create_hour_options();
echo '</div>';
}
public function pickup_time_select_translatable( $value ) {
$value = preg_replace('/(\d)_(\d)/','$1:$2', $value);
$value = explode('_', $value);
$return = __( $value[0], $this->plugin_slug ). ' ' .$value[1];
return $return;
}
public function create_hour_options() {
// Make sure we have a time zone set
$offset = get_option( 'gmt_offset' );
$timezone_setting = get_option( 'timezone_string' );
if ( $timezone_setting ) {
date_default_timezone_set( get_option( 'timezone_string', 'America/New_York' ) );
}
else {
$timezone = timezone_name_from_abbr( null, $offset * 3600, true );
if( $timezone === false ) $timezone = timezone_name_from_abbr( null, $offset * 3600, false );
date_default_timezone_set( $timezone );
}
// Get days closed textarea from settings, explode into an array
$closing_days_raw = trim( get_option( 'local_pickup_hours_closings' ) );
$closing_days = explode( "\n", $closing_days_raw );
$closing_days = array_filter( $closing_days, 'trim' );
// Get delay, interval, and number of days ahead settings
$delay_minutes = get_option( 'local_pickup_delay_minutes', 60 );
$interval = get_option( 'local_pickup_hours_interval', 30 );
$num_days_allowed = get_option( 'local_pickup_days_ahead', 1 );
// Setup time variables for calculations
$today_name = strtolower( date( 'l' ) );
$today_date = date( 'm/d/Y' );
// Create an empty array for our dates
$pickup_options = array();
//Translateble days
__( 'Monday', $this->plugin_slug );
__( 'Tuesday', $this->plugin_slug );
__( 'Wednesday', $this->plugin_slug );
__( 'Thursday', $this->plugin_slug );
__( 'Friday', $this->plugin_slug );
__( 'Saturday', $this->plugin_slug );
__( 'Sunday', $this->plugin_slug );
// Add empty option
$pickup_options[''] = __( 'Select time', $this->plugin_slug );
// Loop through all days ahead and add the pickup time options to the array
for ( $i = 0; $i < $num_days_allowed; $i++ ) {
// Get the date of current iteration
$current_day_name = date( 'l', strtotime( "+$i days" ) );
$current_day_name_lower = strtolower( $current_day_name );
// Get the day's opening and closing times
$open_time = get_option( 'local_pickup_hours_' . $current_day_name_lower . '_start', '10:00' );
$close_time = get_option( 'local_pickup_hours_' . $current_day_name_lower . '_end', '19:00' );
// Today
$tStart = strtotime( $open_time );
$tEnd = strtotime( $close_time );
$tNow = $tStart;
$current_time = time();
// Date format based on user settings
$date_format = get_option('time_format');
$date_format_key = preg_replace("/[^\w]+/", "_", $date_format);
// If Closed today or today's pickup times are over, don't allow a pickup option
if ( ( in_array( $today_date, $closing_days ) || ( $current_time >= $tEnd ) ) && $num_days_allowed == 1 ) {
// Set drop down text to let user know store is closed
$pickup_options['closed_today'] = __( 'Closed today, please check back tomorrow!', $this->plugin_slug );
// Hide Order Review so user doesn't order anything today
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
}
else {
// Create array of time options to return to woocommerce_form_field
// Today
if ( $i == 0) {
// Check if it's not too late for pickup
if ( $current_time < $tEnd ) {
// Fix tNow if is pickup possible today
if ( $i == 0 ) {
$todayStart = $tStart;
$delayStart = strtotime("+$delay_minutes minutes", $current_time);
while ( $todayStart <= $delayStart ) {
$todayStart = strtotime("+$interval minutes", $todayStart);
}
$tNow = $todayStart;
}
while ( $tNow <= $tEnd ) {
$day_name = __( 'Today', $this->plugin_slug );
$option_key = $current_day_name . date( $date_format_key, $tNow );
$option_value = $day_name . ' ' . date( $date_format, $tNow );
$pickup_options[$option_key] = $option_value;
$tNow = strtotime( "+$interval minutes", $tNow );
}
}
// Other days
} else {
if ( !empty($open_time) && !empty($close_time )) {
while ( $tNow <= $tEnd ) {
$day_name = __( $current_day_name, $this->plugin_slug );
$option_key = $current_day_name . date( $date_format_key, $tNow );
$option_value = $day_name . ' ' . date( $date_format, $tNow );
$pickup_options[$option_key] = $option_value;
$tNow = strtotime( "+$interval minutes", $tNow );
}
}
}
}
} // end for loop
if ( count($pickup_options) == 1) {
// Set drop down text to let user know store is closed
$pickup_options['closed_today'] = __( 'Closed today, please check back tomorrow!', $this->plugin_slug );
// Hide Order Review so user doesn't order anything today
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
}
return $pickup_options;
}
The final result would look something like this Drop-down list:
As soon as possible
Tuesday 7:30 pm
Tuesday 8:00 pm
Tuesday 8:30 pm
There is many ways to do it depending if the key value you want for "As soon as possible" choice has to be dynamic. This is done in your first function with array_merge() this way:
public function time_select( $checkout ) {
echo '<div id="local-pickup-time-select"><h2>' . __( 'Delivery Time', $this->plugin_slug ) . '</h2>';
// The default empty value and your translatable sentence to be included
$array_to_insert = array(
'' => __( 'Select your delivery time', $this->plugin_slug ),
'as_soon' => __( 'As soon as possible', $this->plugin_slug )
);
// Getting your calculated hours options array
$options = self::create_hour_options();
// Merging both arrays in one
$options = array_merge( $array_to_insert, $options );
woocommerce_form_field( 'local_pickup_time_select', array(
'type' => 'select',
'class' => array( 'local-pickup-time-select-field form-row-wide' ),
'label' => __( 'Delivery Time', $this->plugin_slug ),
'required' => true,
'options' => $options,
), $checkout->get_value( 'local_pickup_time_select' ));
echo '</div>';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works. you will get that:
I have noticed in your code that your //Translateble days (monday to sunday) are not set in individual variables or in an array…

WP - function working on my localhost(MAC) but in windows server live not working Wordpress 4.1.1

I want all categories in one page with filter .I find a solution . this is working fine in my localhost but in live (Windows server) not working.
Here is this function in functions.php:
/**
* Create terms list.
*
* #since 1.5
*
* #param array $args
*
* #return string
*/
function clpr_terms_list( $args = array() ) {
$defaults = array(
'taxonomy' => 'category',
'exclude' => array(),
'menu' => true,
'count' => true,
'top_link' => true,
'class' => 'terms',
);
$options = wp_parse_args( (array) $args, $defaults );
$options = apply_filters( 'clpr_terms_list_args', $options );
$terms = get_terms( $options['taxonomy'], array( 'hide_empty' => 0, 'child_of' => 0, 'pad_counts' => 0, 'app_pad_counts' => 1 ) );
$navigation = '';
$list = '';
$groups = array();
if ( empty( $terms ) || ! is_array( $terms ) )
return html( 'p', __( 'Sorry, but no terms were found.', 'Couponize' ) );
// unset child terms
foreach ( $terms as $key => $value ) {
if ( $value->parent != 0 )
unset( $terms[ $key ] );
}
foreach ( $terms as $term ) {
$letter = mb_strtoupper( mb_substr( $term->name, 0, 1 ) );
if ( is_numeric( $letter ) )
$letter = '#';
if ( ! empty( $letter ) )
$groups[ $letter ][] = $term;
}
if ( empty( $groups ) )
return;
foreach ( $groups as $letter => $terms ) {
$old_list = $list;
$old_navigation = $navigation;
$letter_items = false;
$letter = apply_filters( 'the_title', $letter );
$letter_id = ( preg_match( '/\p{L}/', $letter ) ) ? $letter : substr( md5( $letter ), 0, 5 ); // hash special chars
$navigation .= html_link( '#' . $options['class'] . '-' . $letter_id, $letter );
$top_link = ( $options['top_link'] ) ? html_link( '#top', __( 'Top', 'Couponize' ) . ' ↑' ) : '';
$list .= '<h2 class="' . $options['class'] . '" id="' . $options['class'] . '-' . $letter_id . '">' . $letter . $top_link . '</h2>';
$list .= '<ul class="' . $options['class'] . '">';
foreach ( $terms as $term ) {
if ( in_array( $term->term_id, $options['exclude'] ) )
continue;
$letter_items = true;
$name = apply_filters( 'the_title', $term->name );
$link = html_link( get_term_link( $term, $options['taxonomy'] ), $name );
$count = ( $options['count'] ) ? ' (' . intval( $term->count ) . ')' : '';
$list .= html( 'li', $link . $count );
}
$list .= '</ul>';
if ( ! $letter_items ) {
$list = $old_list;
$navigation = $old_navigation;
}
}
$navigation = html( 'div class="grouplinks"', $navigation );
if ( $options['menu'] )
$list = $navigation . $list;
return $list;
}
/**
* Create categories list.
*
* #since 1.5
*
* #return string
*/
function clpr_categories_list() {
$args = array(
'taxonomy' => 'category',
'class' => 'categories',
);
return clpr_terms_list( $args );
}
/**
* Create stores list.
*
* #since 1.5
*
* #return string
*/
function clpr_stores_list() {
$args = array(
'taxonomy' => 'category',
'class' => 'stores',
);
return clpr_terms_list( $args );
}
I am trying to echo this function in template file.
<?php echo clpr_stores_list(); ?>
But not working. please help me.
Thanks

Get orders by date and status woocommerce

I need get a list of orders in woocommerce passing start date, final date and status.
I tryed use some techniques like described by Mike Jolley, and I mixed with this. But I have not had success. This return all orders. I´m using the woocommerce version 2.2.10.
Thanks for help.
My code:
public function get_orders(){
global $json_api;
$initial_date = $json_api->query->para1;
$final_date = $json_api->query->para2;
$order_id = $json_api->query->para3;
$status_order = $json_api->query->para4;
define('GET_ORDERS_FILTER_DATE_FROM', $initial_date );
define('GET_ORDERS_FILTER_DATE_TO', $final_date );
add_filter('posts_where', array( __CLASS__, 'get_orders_where_dates_between') );
$orders = get_posts( array(
'post_type' => 'shop_order',
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => array_keys( $status_order )
) );
remove_filter('posts_where', 'order_page_get_orders_where_dates_between');
return $orders;
}
function get_orders_where_dates_between( $where ){
global $wpdb;
if( ! defined('GET_ORDERS_FILTER_DATE_FROM') || ! defined('PARCELWARE_GET_ORDERS_FILTER_DATE_TO') )
return $where;
$where .= $wpdb->prepare(" AND post_date >= '%s' ", GET_ORDERS_FILTER_DATE_FROM);
$where .= $wpdb->prepare(" AND post_date <= '%s' ", GET_ORDERS_FILTER_DATE_TO);
return $where;
}
You can use wc_get_orders
$initial_date = yyyy-mm-dd;
$final_date = yyyy-mm-dd;
$orders = wc_get_orders(array(
'limit'=>-1,
'type'=> 'shop_order',
'status'=> array( 'wc-completed','wc-refunded' ),
'date_created'=> $initial_date .'...'. $final_date
)
);
How about using custom wpdb query like this?
global $wpdb;
$date_from = '2015-11-20';
$date_to = '2015-12-20';
$post_status = implode("','", array('wc-processing', 'wc-completed') );
$result = $wpdb->get_results( "SELECT * FROM $wpdb->posts
WHERE post_type = 'shop_order'
AND post_status IN ('{$post_status}')
AND post_date BETWEEN '{$date_from} 00:00:00' AND '{$date_to} 23:59:59'
");
echo "<pre>";
print_r($result);
If you want to use timestamps (date AND time):
$timestamp_start = '2022-04-07 20:00:00.000'; // example
$timestamp_end = '2022-04-21 20:00:01.000'; // example
'date_created' => strtotime($timestamp_start ) .'...'. strtotime($timestamp_end)

Customising excerpt in theme

I've been reading a lot of how to customize excerpt function in WordPress but I have no idea how to proceed with this.
The theme that I am using already have 4 pre-customized excerpt functions and the one that I will show here is closest to my desired but still needs to improve.
My question is how to stop erasing HTML formating from my content (line breaks, paragraphs, font variants, etc)?
add_shortcode('display_news_s5', 'be_display_posts_shortcode5');
function be_display_posts_shortcode5($atts) {
// Pull in shortcode attributes and set defaults
extract( shortcode_atts( array(
'post_type' => 'post',
'post_parent' => false,
'id' => false,
'tag' => '',
'category' => '',
'offset' => 0,
'posts_per_page' => '1',
'order' => 'DESC',
'orderby' => 'date',
'include_date' => false,
'include_excerpt' => false,
'excerpt_l' => 8,
'taxonomy' => false,
'tax_term' => true,
'tax_operator' => 'IN'
), $atts ) );
// Set up initial query for post
$args = array(
'post_type' => explode( ',', $post_type ),
'tag' => $tag,
'category_name' => $category,
'p' => $id,
'posts_per_page' => $posts_per_page,
'order' => $order,
'orderby' => $orderby,
'offset' => $offset
);
// If Post IDs
if( $id ) {
$posts_in = explode( ',', $id );
$args['post__in'] = $posts_in;
}
// If taxonomy attributes, create a taxonomy query
if ( !empty( $taxonomy ) && !empty( $tax_term ) ) {
// Term string to array
$tax_term = explode( ', ', $tax_term );
// Validate operator
if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
$tax_operator = 'IN';
$tax_args = array(
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $tax_term,
'operator' => $tax_operator
)
)
);
$args = array_merge( $args, $tax_args );
}
// If post parent attribute, set up parent
if( $post_parent ) {
if( 'current' == $post_parent ) {
global $post;
$post_parent = $post->ID;
}
$args['post_parent'] = $post_parent;
}
$listing = new WP_Query( apply_filters( 'display_posts_shortcode_args', $args, $atts ) );
$count = 0;
if ( !$listing->have_posts() )
return apply_filters ('display_posts_shortcode_no_results', false );
$inner = '';
while ( $listing->have_posts() ): $listing->the_post(); global $post;
$count++;
if( $count == 1 ){
$style = ' news-main-post';
} else {
$style = ' news-list-posts';
}
$title = '<div class="news-listing-title"><a class="title" href="'. get_permalink() .'">'. get_the_title() .'</a></div>';
if ($include_date == 'true') $date = ' <div class="news-listing-meta"><span class="news-listing-date">'. get_the_date() . '</span><span class="news-listing-comment">('. get_comments_number() .')</span></div>';
else $date = '';
if ($include_excerpt == 'true') $excerpt = '<span>' .excerpt($excerpt_l) . '</span>';
else $excerpt = '';
$output = '<div class="news-listing' . $style . '"><div class="news-listing-item">'. $title . $excerpt . $date . '</div></div>';
$inner .= apply_filters( 'display_posts_shortcode_output', $output, $atts, $title, $excerpt, $date );
endwhile; wp_reset_query();
$open = apply_filters( 'display_posts_shortcode_wrapper_open', '<div class="news-listing-wrapper-s3">' );
$close = apply_filters( 'display_posts_shortcode_wrapper_close', '<div class="clear"></div></div>' );
$return = $open . $inner . $close;
return $return;
}
Have a look here: LINK looks like its doing what you want to acchieve.

Remove from Array if Contains Lowercase Letter

I have a number of WordPress posts that will each have two tags, one tag is the State and the other tag is an Airport Code.
I'm able to generate a dropdown menu from the tags using the instructions here: http://www.wprecipes.com/wordpress-hack-display-your-tags-in-a-dropdown-menu
But, I would like to actually have two different dropdowns, one that lists the States in alpha order, the other lists the Airports in alpha order. Every Airport will always be three uppercase letters. Is there an argument that I can add to to this so that I can create one dropdown for Airports and another for States?
If it contains a lowercase letter, it goes in the State dropdown. If no lowercase, it's an airport.
I modify the snippet from your attached tutorials into something like this:
function dropdown_tag_cloud( $args = '' ) {//supported: 'all', 'airport', 'state'
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'exclude' => '', 'include' => '', 'tags_mode' => 'all'
);
$args = wp_parse_args( $args, $defaults );
print_r($args);
$tags = get_tags( array_merge($args, array('orderby' => 'count', 'order' => 'DESC')) ); // Always query top tags
if ( empty($tags) )
return;
$return = dropdown_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
if ( is_wp_error( $return ) ){
echo "wp error...";
return false;
}else
echo apply_filters( 'dropdown_tag_cloud', $return, $args );
}
function dropdown_generate_tag_cloud( $tags, $args = '' ) {
global $wp_rewrite;
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'
);
$args = wp_parse_args( $args, $defaults );
extract($args);
if ( !$tags )
return;
$counts = $tag_links = array();
foreach ( (array) $tags as $tag ) {
if($tags_mode == 'airport'){
//if uppercased tag is equal to the tag
//which means current tag already uppercased.
if(!(strtoupper($tag->name) == $tag->name))
continue;//skip current tag
} else if($tags_mode == 'state'){
//if uppercased tag is equal to the tag
//which means current tag already uppercased.
if((strtoupper($tag->name) == $tag->name))
continue;//skip current tag
}
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link( $tag->term_id );
if ( is_wp_error( $tag_links[$tag->name] ) )
return $tag_links[$tag->name];
$tag_ids[$tag->name] = $tag->term_id;
}
$min_count = min($counts);
$spread = max($counts) - $min_count;
if ( $spread <= 0 )
$spread = 1;
$font_spread = $largest - $smallest;
if ( $font_spread <= 0 )
$font_spread = 1;
$font_step = $font_spread / $spread;
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
if ( 'name' == $orderby )
uksort($counts, 'strnatcasecmp');
else
asort($counts);
if ( 'DESC' == $order )
$counts = array_reverse( $counts, true );
$a = array();
$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
foreach ( $counts as $tag => $count ) {
$tag_id = $tag_ids[$tag];
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', wp_specialchars( $tag ));
$a[] = "\t<option value='$tag_link'>$tag ($count)</option>";
}
switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\n\t<li>";
$return .= join("</li>\n\t<li>", $a);
$return .= "</li>\n</ul>\n";
break;
default :
$return = join("\n", $a);
break;
endswitch;
return apply_filters( 'dropdown_generate_tag_cloud', $return, $tags, $args );
}
Basically, I was just adding new parameter called tags_mode with the following parameter supported:
all
airport
state
And then, in dropdown_generate_tag_cloud(), I add this code:
if($tags_mode == 'airport'){
if(!(strtoupper($tag->name) == $tag->name))
continue;//skip current tag
} else if($tags_mode == 'state'){
if((strtoupper($tag->name) == $tag->name))
continue;//skip current tag
}
The main idea in this added snippet is this:
strtoupper($tag->name) == $tag->name
It work like this: if the uppercased tag name is equal to the original tag name. That means, current tag is already uppercased (or, equal to airport code).
To implement it, just do as the tutorial says. Only, you need to add new parameter:
<?php dropdown_tag_cloud('number=0&order=asc&tags_mode=state'); ?>
Notice the &tags_mode=state
Just try it out and tell me if this is what you want.

Categories