Plugin Directory

Changeset 619000


Ignore:
Timestamp:
10/30/2012 01:36:33 PM (12 years ago)
Author:
ajayver
Message:

Added permalink support

Location:
cat-tag-filter-widget
Files:
11 added
2 edited

Legend:

Unmodified
Added
Removed
  • cat-tag-filter-widget/trunk/cat-tag-filter.php

    r609238 r619000  
    55Description: This plugin adds a widget to your WordPress site that allows your visitors to filter posts by category and tag.
    66Author: Ajay Verma
    7 Version: 0.8.5
     7Version: 0.9
    88Author URI: http://ajayver.com/
    99*/
     
    1616    $cat = '';  //initialize variables for category and tag parts of the url
    1717    $tag = '';
    18     $tag_prefix = '?'. $_POST["tag_prefix"] .'='; //get tag and category prefix
    19     $cat_prefix = '?'. $_POST["cat_prefix"] .'=';
     18    $tag_prefix = $_POST["tag_prefix"] .'/'; //get tag and category prefix
     19    $cat_prefix = $_POST["cat_prefix"] .'/';
    2020    if ($_POST["tag_logic"] == 1) $tag_logic = '+'; //logic for tags (AND or OR)
    2121    else $tag_logic = ',';
     
    2323        $_POST['cat'] = get_term($_POST['cat'], $_POST['category_tax']); //get category slug from it's id
    2424        $cat = '/'. $cat_prefix . $_POST['cat']->slug; //add it to category part of the url
    25         $tag_prefix = '&' . $_POST["tag_prefix"] . '='; //add & to tag part of url
     25        $tag_prefix = '/' . $_POST["tag_prefix"] . '/'; //add & to tag part of url
    2626    }
    2727
     
    3737   
    3838    if ($cat == '' && $tag == '' && $_POST["blog_url"] != '') $url = $_POST["home_url"] . '/' . $_POST["blog_url"]; //if no category or no tag was chosen, just create a link to blog
    39     else $url = $_POST["home_url"] . $cat . $tag;  //else, create a link to blog + category and tag arguments
     39    else $url = $_POST["home_url"]. '/' . $cat . $tag;  //else, create a link to blog + category and tag arguments
    4040    header('Location: ' . $url); //redirect user to the created url
    4141    exit;
     
    217217    <input type="hidden" name="tag_logic" value="<?php echo $ctf_options['tag_logic'] ?>" />
    218218    <?php $taxonomies=get_taxonomies('','',''); ?>
    219     <input type="hidden" name="tag_prefix" value="<?php echo $taxonomies[$ctf_options['tag_tax']]->query_var ?>" />
     219    <input type="hidden" name="tag_prefix" value="<?php echo $taxonomies[$ctf_options['tag_tax']]->rewrite['slug'] ?>" />
    220220    <input type="hidden" name="category_tax" value="<?php echo $ctf_options['category_tax'] ?>" />
    221     <input type="hidden" name="cat_prefix" value="<?php echo $taxonomies[$ctf_options['category_tax']]->query_var ?>" />
     221    <input type="hidden" name="cat_prefix" value="<?php echo $taxonomies[$ctf_options['category_tax']]->rewrite['slug'] ?>" />
    222222    <input id="ctf-submit" class="button" type="submit"  value="<?php echo $ctf_options['button_title']; ?>"/> 
    223223  </form> 
     
    234234    parent::WP_Widget(false, $name = 'Cat + Tag Filter', $widget_ops); 
    235235  }
     236
     237
    236238  /** @see WP_Widget::widget */
    237239  function widget($args, $instance) {   
     
    260262    echo $before_widget;
    261263    if ( $ctf_options['title'] ) echo $before_title . $ctf_options['title'] . $after_title;
     264
    262265    ctf_widget();
    263266    echo $after_widget;
     
    430433   
    431434  <?php
    432   }
     435
     436  }
     437
    433438} // class Cat + Tag Filter
    434439// register Cat + Tag Filter widget
     
    438443    }
    439444add_action('widgets_init', create_function('', 'return register_widget("cat_tag_filter");'));
     445
     446function add_rewrite_rules() {
     447    global $wp_rewrite;
     448    $ctf_options = get_option('widget_cat_tag_filter');
     449    foreach ($ctf_options as $widget_options){
     450        if ($widget_options['category_tax']){
     451       
     452            $taxonomies = get_taxonomies('','','');
     453       
     454            $new_rules = array(
     455                 $taxonomies[$widget_options['category_tax']]->rewrite['slug'] . '/(.+?)/' . $taxonomies[$widget_options['tag_tax']]->rewrite['slug'] . '/(.+?)/?$' => 'index.php?' . $taxonomies[$widget_options['category_tax']]->query_var . '=' . $wp_rewrite->preg_index(1) . '&' . $taxonomies[$widget_options['tag_tax']]->query_var . '=' . $wp_rewrite->preg_index(2)
     456            );
     457            $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
     458
     459            }
     460        }
     461   
     462
     463   
     464    }
     465   
     466
     467add_action( 'generate_rewrite_rules', 'add_rewrite_rules' );
     468
     469
     470
    440471?>
  • cat-tag-filter-widget/trunk/readme.txt

    r609235 r619000  
    7474== Changelog ==
    7575
     76= 0.9 =
     77* Added permalink support.
     78
    7679= 0.8.4 =
    7780* Added an option to switch off corresponding tags mode.
Note: See TracChangeset for help on using the changeset viewer.