Plugin Directory

Changeset 810295


Ignore:
Timestamp:
11/25/2013 06:24:39 PM (12 years ago)
Author:
LordPretender
Message:

2.0.0 released !

Location:
posts-order-widget
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • posts-order-widget/trunk/post-order-widget.php

    r809236 r810295  
    1414load_plugin_textdomain('post-order-widget', false, dirname( plugin_basename( __FILE__ ) ). '/languages/');
    1515
     16require( rtrim(plugin_dir_path(__FILE__), '/') . '/taxonomy.class.php');
     17$pow_taxonomy = new POW_Taxonomy();
     18
    1619//S'inspirer de wp-includes/default-widgets.php
    1720$id_bytitle = "bytitle";
     
    2023$id_rand = "rand";
    2124
     25//Modification de l'ordre d'affichage des articles et initialisation de divers attributs de la classe POW_Taxonomy.
     26add_filter('pre_get_posts', array($pow_taxonomy, 'frontend_initialiser'), -100);
     27
    2228//Déclaration de notre extention en tant que Widget
    2329function register_POW_Widget() {
     
    2531}
    2632add_action( 'widgets_init', 'register_POW_Widget' );
    27 
    28 //Lecture du filtre choisi et initialisation pour utilisation lors du chargement des articles
    29 function POW_pre_get_posts($vars) {
    30     $params = POW_getOrderBySelect();
    31 
    32     $vars->set('orderby', $params['orderby']);
    33     $vars->set('order', $params['order']); 
    34     //$vars->set('ignore_sticky_posts', 1); 
    35 
    36     return $vars;
    37 }
    38 add_filter('pre_get_posts', 'POW_pre_get_posts');
    39 
    40 //Retourne le filtre à utiliser en fonction du choix de l'utilisateur
    41 function POW_getOrderBySelect() {
    42     $result = array(); 
    43 
    44     //Lecture du choix de l'utilisateur
    45     $selection = isset($_GET['pow']) ? $_GET['pow'] : 'dated';
    46    
    47     switch ($selection) {
    48        
    49         //Sélection par défaut : Tri du plus récent au plus ancien
    50         case 'dated':
    51             $result['orderby'] = "date";
    52             $result['order'] = "DESC";
    53 
    54             break;
    55        
    56         //Tri du plus ancien au plus récent
    57         case 'datea':
    58             $result['orderby'] = "date";
    59             $result['order'] = "ASC";
    60 
    61             break;
    62        
    63         //Tri du plus ancien au plus récent
    64         case 'title':
    65             $result['orderby'] = "title";
    66             $result['order'] = "ASC";
    67 
    68             break;
    69        
    70         //Pour les cas simples, la valeur de l'item de la combo correspond à ce qui sera utilisé dans le "order by" de la requête SQL.
    71         default:
    72             $result['orderby'] = $selection;
    73             $result['order'] = "DESC";
    74            
    75     }
    76    
    77     //Sélectionne l'item précédemment choisi par l'utilisateur
    78     $result[$selection] = ' selected="selected"';
    79    
    80     return $result;
    81 }
    82 add_filter('wp_head', 'POW_getOrderBySelect');
    8333
    8434// Documentation : http://codex.wordpress.org/Widgets_API
     
    10555     */
    10656    public function widget( $args, $instance ) {
    107         global $id_bytitle, $id_bydatea, $id_bymodified, $id_rand;
     57        global $id_bytitle, $id_bydatea, $id_bymodified, $id_rand, $pow_taxonomy;
    10858       
    10959        //On n'affiche pas le widget si nous sommes dans une page, un article, un média.
    110         if(is_page() || is_single() || is_attachment())return;
    111        
    11260        if(is_page() || is_single() || is_attachment())return;
    11361       
     
    11866        if ( ! empty( $title ) )echo $args['before_title'] . $title . $args['after_title'];
    11967       
    120         $params = POW_getOrderBySelect();
     68        //Ajout des options en fonction des paramètres du widget
     69        $opt_title = $instance[$id_bytitle] ? $pow_taxonomy->getHTMLOption("title") : "";
     70        $opt_bydatea = $instance[$id_bydatea] ? $pow_taxonomy->getHTMLOption("datea") : "";
     71        $opt_bymodified = $instance[$id_bymodified] ? $pow_taxonomy->getHTMLOption("modified") : "";
     72        $opt_rand = $instance[$id_rand] ? $pow_taxonomy->getHTMLOption("rand") : "";
     73        $opt_bydated = $pow_taxonomy->getHTMLOption("dated");
    12174       
    122         //Ajout des options en fonction des paramètres du widget
    123         $opt_title = $instance[$id_bytitle] ? "<option value=\"title\"{$params['title']}>". __('By title', 'post-order-widget'). "</option>" : "";
    124         $opt_bydatea = $instance[$id_bydatea] ? "<option value=\"datea\"{$params['datea']}>". __('Oldest to newest', 'post-order-widget'). "</option>" : "";
    125         $opt_bymodified = $instance[$id_bymodified] ? "<option value=\"modified\"{$params['modified']}>". __('By modification', 'post-order-widget'). "</option>" : "";
    126         $opt_rand = $instance[$id_rand] ? "<option value=\"rand\"{$params['rand']}>". __('Randomly', 'post-order-widget'). "</option>" : "";
    127 
    12875        echo "
    12976        <form method=\"get\" id=\"order\">
    13077            <select name=\"pow\" onchange=\"this.form.submit()\">
    13178              $opt_title
    132               <option value=\"dated\"{$params['dated']}>". __('Newest to oldest', 'post-order-widget'). "</option>
     79              $opt_bydated
    13380              $opt_bydatea
    13481              $opt_bymodified
  • posts-order-widget/trunk/readme.txt

    r809236 r810295  
    55Requires at least: 3.6.1
    66Tested up to: 3.6.1
    7 Stable tag: 1.3.2
     7Stable tag: 2.0.0
    88
    99Add the ability to sort the posts by context rather than descending date.
     
    1919* randomly
    2020
    21 You can find a demo here : http://www.apreslafindumonde.fr/
     21You can find a demo here : http://www.spoils.fr/
    2222The widget is named "Trier les articles" on the sidebar.
    2323
     
    3333* 3 checkboxes in order to display or not items in the drop-down list.
    3434
     35Since the version 2.0.0, it is now possible to change the default order for your categories.
     36In the category editing page, you will now find a dropdown list.
     37
    3538== Screenshots ==
    3639
    37401. **From the backend, in the widget management page :** There is severals options in order to display (or not) items in the drop-down list.
    38412. **From the frontend, in the widget area.**
     423. **From the backend, when editing a category : There is a dropdown list in order to select the default order.**
    3943
    4044== Changelog ==
     45
     46= 2.0.0 =
     47* Plugin entirely re-encoded.
     48* It is now possible to define the default order for taxonomies (eg : category, tag, ...).
    4149
    4250= 1.3.2 =
Note: See TracChangeset for help on using the changeset viewer.