Changeset 1202863
- Timestamp:
- 07/21/2015 05:55:17 AM (11 years ago)
- Location:
- post-index/trunk
- Files:
-
- 3 edited
-
php/postsummary.php (modified) (6 diffs)
-
post-index.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
post-index/trunk/php/postsummary.php
r1196902 r1202863 22 22 } 23 23 24 function getCustomFieldValue($fieldName, $alternative ) {24 function getCustomFieldValue($fieldName, $alternative = null) { 25 25 $customFieldValues = get_post_custom_values($fieldName); 26 26 if(is_null($customFieldValues)) { … … 41 41 } 42 42 43 function parse($category_name, $groupBy, $ categoryslug = '', $post_type = null) {43 function parse($category_name, $groupBy, $groupByCf = null, $categoryslug = '', $post_type = null) { 44 44 $category = NULL; 45 45 … … 95 95 while (have_posts()) : the_post(); 96 96 $title = $this->getCustomFieldValue('book_title', get_the_title()); 97 $author = $this->getCustomFieldValue('book_author' , NULL);97 $author = $this->getCustomFieldValue('book_author'); 98 98 99 99 … … 102 102 if(!empty($this->foreignLinks)) { 103 103 foreach($this->foreignLinks as $name => $urlField) { 104 $url = $this->getCustomFieldValue($urlField , NULL);104 $url = $this->getCustomFieldValue($urlField); 105 105 if(!is_null($url)) 106 106 $linkList[] = array ( 'name' => $name, 'url' => $url ); … … 113 113 , 'linkList' => $linkList ); 114 114 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') { 118 129 $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; 124 134 ++$this->itemCount[$c->cat_name]; 125 135 } 126 136 } 127 } else { 137 } else { 128 138 $this->items[$firstLetter][] = $curItem; 129 139 ++$this->itemCount; … … 132 142 133 143 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 } 134 154 135 155 // Reset Query -
post-index/trunk/post-index.php
r1201863 r1202863 71 71 , 'columns' => 1 72 72 , 'show_letter' => true 73 , 'groupby_cf' => null 73 74 ) 74 75 , $atts … … 85 86 86 87 ob_start(); 87 $ps->parse($category, $groupby, $ categoryslug, $post_type);88 $ps->parse($category, $groupby, $groupby_cf, $categoryslug, $post_type); 88 89 $ps->printOut($columns, $show_letter); 89 90 -
post-index/trunk/readme.txt
r1201863 r1202863 66 66 * **category**: Lists all entries that are in the given category, searched by it's name. 67 67 * **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` 69 69 * **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. 70 70 * **columns**: The amount of columns. Default is 1. 71 71 * **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. 72 73 73 74 == Upgrade Notice == … … 85 86 86 87 == 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. 87 92 88 93 = 0.7.4 =
Note: See TracChangeset
for help on using the changeset viewer.