Plugin Directory

Changeset 459937


Ignore:
Timestamp:
11/06/2011 02:16:51 PM (14 years ago)
Author:
subzane
Message:
 
Location:
norman-advanced-archive-widget/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • norman-advanced-archive-widget/trunk/norman-adv-archive.php

    r458720 r459937  
    1919    Description: Norman Advanced Archive Widget is a free replacement for the standard WordPress archive widget. Lots of customization options to satisfy your needs.
    2020    Author: Andreas Norman
    21     Version: 1.0
     21    Version: 1.1
    2222    Author URI: http://www.andreasnorman.se
    2323*/
     
    2929    }
    3030   
    31     function get_years() {
     31    function get_years($current_category_id) {
     32        global $wpdb;
     33       
     34        if ($current_category_id) {
     35        $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($current_category_id)");
     36            $join = apply_filters('getarchives_join', " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)");
     37        } else {
     38        $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'");
     39            $join = apply_filters('getarchives_join', "");
     40        }
     41
     42    $sql = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts ";
     43    $sql .="FROM {$wpdb->posts} {$join} {$where} ";
     44    $sql .="GROUP BY YEAR(post_date) ORDER BY post_date DESC";
     45
     46    return $wpdb->get_results($sql);
     47    }
     48
     49    function get_months($year, $current_category_id) {
    3250        global $wpdb;
    3351
    34         $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'");
    35         $join = apply_filters('getarchives_join', "");
    36 
    37         $sql = "SELECT DISTINCT YEAR(post_date) AS `year`, count(ID) as posts ";
    38         $sql .="FROM {$wpdb->posts} {$join} {$where} ";
    39         $sql .="GROUP BY YEAR(post_date) ORDER BY post_date DESC";
    40 
    41         return $wpdb->get_results($sql);
    42     }
    43 
    44     function get_months($year) {
    45         global $wpdb;
    46 
    47         $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year}");
    48         $join = apply_filters('getarchives_join', "");
     52            if ($current_category_id) {
     53            $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year} AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($current_category_id)");
     54                $join = apply_filters('getarchives_join', " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)");
     55            } else {
     56            $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year}");
     57            $join = apply_filters('getarchives_join', "");
     58            }
    4959
    5060        $sql = "SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts ";
     
    5565    }
    5666
    57     function get_posts($year, $month) {
    58         global $wpdb;
    59 
    60         if (empty($year) || empty($month))
    61             return null;
    62 
     67    function get_posts($year, $month, $current_category_id) {
     68    global $wpdb;
     69
     70    if (empty($year) || empty($month))
     71        return null;
     72
     73        if ($current_category_id) {
     74        $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year} AND MONTH(post_date) = {$month} AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ($current_category_id)");
     75            $join = apply_filters('getarchives_join', " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)");
     76        } else {
    6377        $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = {$year} AND MONTH(post_date) = {$month}");
    6478        $join = apply_filters('getarchives_join', "");
    65 
    66         $sql = "SELECT ID, post_title, post_name FROM {$wpdb->posts} ";
    67         $sql .="$join $where ORDER BY post_date DESC";
    68 
    69         return $wpdb->get_results($sql);
     79        }
     80
     81    $sql = "SELECT ID, post_title, post_name FROM {$wpdb->posts} ";
     82    $sql .="$join $where ORDER BY post_date DESC";
     83
     84    return $wpdb->get_results($sql);
    7085    }   
    7186
     
    7994        $jsexpand = empty($instance['jsexpand']) ? 0 : $instance['jsexpand'];
    8095        $groupbyyear = empty($instance['groupbyyear']) ? 0 : $instance['groupbyyear'];
     96        $limitbycategory = empty($instance['limitbycategory']) ? 0 : $instance['limitbycategory'];
     97        #$hideonnoncategory = empty($instance['hideonnoncategory']) ? 0 : $instance['hideonnoncategory'];
    8198        $title = empty($instance['title']) ? 'Archive' : $instance['title'];
     99       
     100        if ($limitbycategory) {
     101            $current_category_id = get_query_var('cat');
     102        } else {
     103            $current_category_id = false;
     104        }
     105       
    82106        if ($jsexpand == 1) {
    83107            $groupbyyear = 1;
    84108        }
    85        
    86         $years = $this->get_years();
     109        if ($groupbyyear == 1) {
     110            $jsexpand = 1;
     111        }
     112       
     113        $years = $this->get_years($current_category_id);
    87114        $post_year = $years[0]->year;
    88115       
     
    92119      for ($i = 0; $x < count($years[$i]); $i++) {
    93120            $this_year = $jal_options['expandcurrent'] && $years[$i]->year == $post_year;
    94             $months = $this->get_months($years[$i]->year);
     121            $months = $this->get_months($years[$i]->year, $current_category_id);
    95122           
    96123            if ($groupbyyear) {
     
    167194        $instance['jsexpand'] = strip_tags($new_instance['jsexpand']);
    168195        $instance['groupbyyear'] = strip_tags($new_instance['groupbyyear']);
     196        $instance['limitbycategory'] = strip_tags($new_instance['limitbycategory']);
     197        #$instance['hideonnoncategory'] = strip_tags($new_instance['hideonnoncategory']);
    169198       
    170199        return $instance;
     
    178207        $jsexpand = empty($instance['jsexpand']) ? 0 : esc_attr($instance['jsexpand']);
    179208        $groupbyyear = empty($instance['groupbyyear']) ? 0 : esc_attr($instance['groupbyyear']);
     209        $limitbycategory = empty($instance['limitbycategory']) ? 0 : esc_attr($instance['limitbycategory']);
     210        #$hideonnoncategory = empty($instance['hideonnoncategory']) ? 0 : esc_attr($instance['hideonnoncategory']);
     211       
    180212        if ($jsexpand == 1) {
    181213            $groupbyyear = 1;
     
    191223
    192224    <p>
    193       <label for="<?php echo $this->get_field_id('groupbyyear'); ?>"><?php _e('Group By Year (Collaps list):'); ?></label>
     225      <input <?php echo ($limitbycategory=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('limitbycategory'); ?>" name="<?php echo $this->get_field_name('limitbycategory'); ?>" type="checkbox" value="1" />
     226      <label for="<?php echo $this->get_field_id('limitbycategory'); ?>"><?php _e('Limit to current category'); ?></label>
     227    </p>
     228
     229<!--
     230    <p>
     231      <input <?php echo ($hideonnoncategory=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('hideonnoncategory'); ?>" name="<?php echo $this->get_field_name('hideonnoncategory'); ?>" type="checkbox" value="1" />
     232      <label for="<?php echo $this->get_field_id('hideonnoncategory'); ?>"><?php _e('Hide on none category pages'); ?></label>
     233    </p>
     234-->
     235    <p>
    194236      <input <?php echo ($groupbyyear=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('groupbyyear'); ?>" name="<?php echo $this->get_field_name('groupbyyear'); ?>" type="checkbox" value="1" />
    195     </p>
    196 
    197     <p>
    198       <label for="<?php echo $this->get_field_id('jsexpand'); ?>"><?php _e('Collaps list (Groups by year):'); ?></label>
     237      <label for="<?php echo $this->get_field_id('groupbyyear'); ?>"><?php _e('Group By Year (Collaps list)'); ?></label>
     238    </p>
     239
     240    <p>
    199241      <input <?php echo ($jsexpand=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('jsexpand'); ?>" name="<?php echo $this->get_field_name('jsexpand'); ?>" type="checkbox" value="1" />
    200     </p>
    201 
    202     <p>
    203       <label for="<?php echo $this->get_field_id('showcount'); ?>"><?php _e('Show Count:'); ?></label>
     242      <label for="<?php echo $this->get_field_id('jsexpand'); ?>"><?php _e('Collaps list (Groups by year)'); ?></label>
     243    </p>
     244
     245    <p>
    204246      <input <?php echo ($showcount=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('showcount'); ?>" name="<?php echo $this->get_field_name('showcount'); ?>" type="checkbox" value="1" />
    205     </p>
    206 
    207     <p>
    208       <label for="<?php echo $this->get_field_id('linkcounter'); ?>"><?php _e('Include count in link:'); ?></label>
     247      <label for="<?php echo $this->get_field_id('showcount'); ?>"><?php _e('Show Count'); ?></label>
     248    </p>
     249
     250    <p>
    209251      <input <?php echo ($linkcounter=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('linkcounter'); ?>" name="<?php echo $this->get_field_name('linkcounter'); ?>" type="checkbox" value="1" />
    210     </p>
    211 
    212     <p>
    213       <label for="<?php echo $this->get_field_id('truncmonth'); ?>"><?php _e('Truncate month name:'); ?></label>
     252      <label for="<?php echo $this->get_field_id('linkcounter'); ?>"><?php _e('Include count in link'); ?></label>
     253    </p>
     254
     255    <p>
    214256      <input <?php echo ($truncmonth=='1'?'checked="checked"':''); ?> id="<?php echo $this->get_field_id('truncmonth'); ?>" name="<?php echo $this->get_field_name('truncmonth'); ?>" type="checkbox" value="1" />
     257      <label for="<?php echo $this->get_field_id('truncmonth'); ?>"><?php _e('Truncate month name'); ?></label>
    215258    </p>
    216259
  • norman-advanced-archive-widget/trunk/readme.txt

    r458720 r459937  
    1515= Features: =
    1616
    17 * Group monthly archives by year
     17* Option to limit display of archive by current category. Only the posts in the current category will be listed
     18* Option to group monthly archives by year
    1819* JQuery powered fold to show and hide monthly archives in a year.
    1920* Option to truncate month names or not.
    20 * Show/Hide archive count and the design option to decide if you want the count to be displayed inside the link or not.
     21* Option to show/hide archive count and the design option to decide if you want the count to be displayed inside the link or not.
    2122
    2223== Installation ==
     
    3839== Changelog ==
    3940
     41= 1.1 =
     42New feature
     43* Option to limit display of archive by current category. Only the posts in the current category will be listed
     44
    4045= 1.0 =
    4146Initial release
Note: See TracChangeset for help on using the changeset viewer.