Plugin Directory

Changeset 444848


Ignore:
Timestamp:
09/28/2011 03:52:51 PM (14 years ago)
Author:
fcc
Message:

added support for list-counts shortcode

Location:
count-shortcode/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • count-shortcode/trunk/count_shortcode.php

    r409314 r444848  
    44Plugin URI: http://
    55Description: Shortcode to count number of posts that match a given set of criteria; provides link to query to display list of matching posts
    6 Version: 1.1
     6Version: 2.0
    77Author: The Federal Communications Commission
    88Author URI: http://fcc.gov/developers
     
    4646add_shortcode( 'count', 'fcc_count_shortcode' );
    4747
     48/**
     49 * List all terms in a given taxonomy, or across all taxonomies
     50 *
     51 * Usage: [list-counts taxonomy="tags"]
     52 * Usage: [list-counts]
     53 * Usage: [list-counts hide_empty="true"]
     54 *
     55 */
     56function fcc_list_taxonomy_shortcodes( $atts, $content = null ) {
     57
     58    $defaults = array( 'taxonomy' => implode( ',', get_taxonomies() ), 'hide_empty' => false );
     59
     60    $atts = shortcode_atts( $defaults, $atts );
     61
     62    $taxs = explode( ',', $atts['taxonomy'] );
     63   
     64    $output = '<div class="counts-list">';
     65   
     66    foreach ( $taxs as $tax ) {
     67
     68        $tax_obj = get_taxonomy( $tax );
     69       
     70        if ( !$tax_obj )
     71            return false;
     72           
     73        if ( !$tax_obj->query_var || !$tax_obj->public )
     74            continue;
     75           
     76        $terms = get_terms( $tax_obj->name );
     77        if ( sizeof( $terms ) == 0)
     78            continue;
     79           
     80        $output .= '<div class="taxonomy ' . $tax .'">';
     81        $output .= '<strong>' . $tax_obj->labels->name . '</strong><ul>';
     82                   
     83        $output .= wp_list_categories( array(
     84                                'taxonomy' => $tax,
     85                                'show_count' => true,
     86                                'echo' => false,
     87                                'title_li' => false,
     88                                'hide_empty' => $atts['hide_empty'],
     89                            ) );
     90       
     91        $output .= "</div>";
     92
     93    }
     94   
     95    $output .= "</div>";
     96   
     97    return $output;
     98
     99}
     100
     101add_shortcode( 'list-counts', 'fcc_list_taxonomy_shortcodes' );
     102
    48103?>
  • count-shortcode/trunk/readme.txt

    r409732 r444848  
    11=== Plugin Name ===
    2 Contributors: fcc, benbalter
     2Contributors: fcc
    33Donate link:
    44Tags: counting, statistics, shortcode, data, queries, links
     
    2929You can also use the post_type argument to specify a post type (page, post, car, etc.)
    3030
     31**List Usage**
     32
     33You can count all terms within a taxonomy, e.g., [list-counts taxonomy="tags"] or across all taxonomies [list-counts].
     34
    3135== Installation ==
    3236
     
    3539== Changelog ==
    3640
     41= 2.0 =
     42* Added ability to display counts of all terms in a taxonomy, or across all taxonomies
     43
    3744= 1.0 =
    3845* Initial Release
Note: See TracChangeset for help on using the changeset viewer.