Plugin Directory

Changeset 1202863


Ignore:
Timestamp:
07/21/2015 05:55:17 AM (11 years ago)
Author:
iTux
Message:

Started development of grouping and sorting by cf.

Location:
post-index/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • post-index/trunk/php/postsummary.php

    r1196902 r1202863  
    2222    }
    2323   
    24     function getCustomFieldValue($fieldName, $alternative) {
     24    function getCustomFieldValue($fieldName, $alternative = null) {
    2525        $customFieldValues = get_post_custom_values($fieldName);
    2626        if(is_null($customFieldValues)) {
     
    4141    }
    4242   
    43     function parse($category_name, $groupBy, $categoryslug = '', $post_type = null) {
     43    function parse($category_name, $groupBy, $groupByCf = null, $categoryslug = '', $post_type = null) {
    4444      $category = NULL;
    4545     
     
    9595        while (have_posts()) : the_post();
    9696            $title = $this->getCustomFieldValue('book_title', get_the_title());
    97             $author = $this->getCustomFieldValue('book_author', NULL);
     97            $author = $this->getCustomFieldValue('book_author');
    9898           
    9999                 
     
    102102            if(!empty($this->foreignLinks)) {
    103103                foreach($this->foreignLinks as $name => $urlField) {
    104                     $url = $this->getCustomFieldValue($urlField, NULL);
     104                    $url = $this->getCustomFieldValue($urlField);
    105105                    if(!is_null($url))
    106106                        $linkList[] = array ( 'name' => $name, 'url' => $url );
     
    113113                            , 'linkList' => $linkList );
    114114
    115             $firstLetter = strtoupper(substr(sanitize_title($title), 0, 1));   
    116            
    117             if($groupBy == 'subcategory') {         
     115            if ($groupByCf) {
     116                $cfValue = $this->getCustomFieldValue($groupByCf);
     117                $curItem['sortValue'] = $cfValue;
     118                if (!$cfValue) {
     119                    continue;
     120                }
     121
     122                $firstLetter = strtoupper(substr(sanitize_title($cfValue), 0, 1));
     123            } else {
     124                $curItem['sortValue'] = $title;
     125                $firstLetter = strtoupper(substr(sanitize_title($title), 0, 1));
     126            }
     127
     128            if($groupBy == 'subcategory') {
    118129                $post_categories = get_the_category();
    119                 $cats = array();
    120    
    121                 foreach($post_categories as $c){                   
    122                     if($c->parent == $categoryId) {
    123                         $this->items[$c->cat_name][$firstLetter][] = $curItem;             
     130
     131                foreach ($post_categories as $c) {
     132                    if ($c->parent == $categoryId) {
     133                        $this->items[$c->cat_name][$firstLetter][] = $curItem;
    124134                        ++$this->itemCount[$c->cat_name];
    125135                    }
    126136                }
    127             } else {   
     137            } else {
    128138                $this->items[$firstLetter][] = $curItem;
    129139                ++$this->itemCount;
     
    132142       
    133143        ksort($this->items, SORT_STRING);
     144
     145        foreach ($this->items as &$elements) {
     146            uasort($elements, function ($a, $b) {
     147                if ($a['sortValue'] == $b['sortValue']) {
     148                    return 0;
     149                }
     150
     151                return ($a['sortValue'] < $b['sortValue']) ? -1 : 1;
     152            });
     153        }
    134154       
    135155        // Reset Query
  • post-index/trunk/post-index.php

    r1201863 r1202863  
    7171                                           , 'columns' => 1
    7272                                           , 'show_letter' => true
     73                                           , 'groupby_cf' => null
    7374                                           )
    7475                                   , $atts
     
    8586
    8687            ob_start();
    87             $ps->parse($category, $groupby, $categoryslug, $post_type);
     88            $ps->parse($category, $groupby, $groupby_cf, $categoryslug, $post_type);
    8889            $ps->printOut($columns, $show_letter);
    8990       
  • post-index/trunk/readme.txt

    r1201863 r1202863  
    6666* **category**: Lists all entries that are in the given category, searched by it's name.
    6767* **categoryslug**: Same as category but searched by the slug.
    68 * **groupby**: Grouping as explaned in `How to change the grouping`
     68* **groupby**: Grouping as explaned in `How to change the grouping`, possible values are `firstLetter`, `subcategory`, and `custom_field`
    6969* **post_type**: The index will be build for the given post type instead of the standard type `post`. Please see [WordPress Codex, Post Types](http://codex.wordpress.org/Post_Types "WordPress Codex, Post Types") for details.
    7070* **columns**: The amount of columns. Default is 1.
    7171* **show_letter**: If set to false, the grouping letter will not be generated.
     72* **groupby_cf**: If defined, the custom field value will be used for grouping and sorting instead of the blog posts title.
    7273
    7374== Upgrade Notice ==
     
    8586
    8687== Changelog ==
     88
     89= 0.7.5 =
     90
     91* Added: Use any custom field value to group your index with. Just specify it in the shortcode like `[post_index groupby_cf='Author']`. It does work together with grouping by subcategory and the default firstLetter grouping.
    8792
    8893= 0.7.4 =
Note: See TracChangeset for help on using the changeset viewer.