Changeset 200947
- Timestamp:
- 02/02/2010 04:09:07 AM (16 years ago)
- Location:
- collapsing-categories/trunk
- Files:
-
- 3 edited
-
collapsFunctions.js (modified) (4 diffs)
-
collapscat.php (modified) (4 diffs)
-
collapscatlist.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
collapsing-categories/trunk/collapsFunctions.js
r197221 r200947 1 /* Collapse Functions, version 1. 61 /* Collapse Functions, version 1.7 2 2 * 3 3 *--------------------------------------------------------------------------*/ … … 133 133 if (theSpan.className!='sym') { 134 134 theSpan = theSpan.childNodes[0]; 135 //alert(childList.getAttribute('id'));136 135 theId = childList.childNodes[0].getAttribute('id'); 137 136 } … … 141 140 src.setAttribute('title','click to expand'); 142 141 theSpan.innerHTML=expand; 142 childList.innerHTML='<li></li>'; 143 143 if (animate==1) { 144 //Effect.BlindUp(childList, {duration: 0.5});145 144 jQuery(childList).hide('blind', '', 500); 146 145 } else { … … 152 151 src.setAttribute('title','click to collapse'); 153 152 theSpan.innerHTML=collapse; 153 childList.innerHTML=subCatPosts[theId]; 154 154 if (animate==1) { 155 //Effect.BlindDown(childList, {duration: 0.5});156 155 jQuery(childList).show('blind', '', 500); 157 156 } else { -
collapsing-categories/trunk/collapscat.php
r200498 r200947 5 5 Description: Uses javascript to expand and collapse categories to show the posts that belong to the category 6 6 Author: Robert Felty 7 Version: 1. 1.17 Version: 1.2 8 8 Author URI: http://robfelty.com 9 9 Tags: sidebar, widget, categories, menu, navigation, posts … … 33 33 34 34 if (!is_admin()) { 35 add_action('wp_head', wp_enqueue_script('jquery')); 36 add_action('wp_head', wp_enqueue_script('collapsFunctions', 37 "$url/wp-content/plugins/collapsing-categories/collapsFunctions.js",'', 38 '1.6')); 35 $inFooter=true; 36 if ($options = get_option('collapsCatOptions') && $options['inFooter']) 37 $inFooter = $options['inFooter']; 38 wp_enqueue_script('collapsFunctions', 39 "$url/wp-content/plugins/collapsing-categories/collapsFunctions.js", 40 array('jquery'), '1.7', true); 39 41 add_action( 'wp_head', array('collapscat','get_head')); 40 42 // add_action( 'wp_footer', array('collapsCat','get_foot')); … … 134 136 include_once( 'collapscatlist.php' ); 135 137 function collapsCat($args='', $print=true) { 138 global $subCatPosts; 136 139 if (!is_admin()) { 137 140 list($posts, $categories, $parents, $options) = … … 164 167 "; 165 168 } 169 //print_r($subCatPosts); 170 echo phpArrayToJS($subCatPosts); 171 // now we create an array indexed by the id of the ul for posts 172 166 173 echo "// ]]>\n</script></li>\n"; 167 174 } else { -
collapsing-categories/trunk/collapscatlist.php
r200498 r200947 2 2 /* 3 3 collapsing categories version: 1.1.1 4 copyright 2007 robert felty 5 6 this work is largely based on the collapsing categories plugin by andrew rader 7 (http://voidsplat.org), which was also distributed under the gplv2. i have tried 8 contacting him, but his website has been down for quite some time now. see the 9 changelog file for more information. 4 copyright 2007-2010 robert felty 10 5 11 6 this file is part of collapsing categories … … 25 20 foundation, inc., 51 franklin st, fifth floor, boston, ma 02110-1301 usa 26 21 */ 22 global $subCatPosts; 23 $subCatPosts = array(); 24 25 26 function phpArrayToJS($array) { 27 /* generates javscript code to create an array from a php array */ 28 $script = "var subCatPosts = new Object();\n"; 29 foreach ($array as $key => $value){ 30 $script .= "subCatPosts['$key'] = '" . 31 addslashes(str_replace("\n", '', $value)) . "';\n"; 32 } 33 return($script); 34 } 35 27 36 28 37 function add_to_includes($cat, $inexclusionarray) { … … 69 78 function miscPosts($cat,$catlink,$subcatpostcount2, $posttext) { 70 79 /* this function will group posts into a miscellaneous sub-category */ 71 global $options, $expandSym, $collapseSym, $expandSymJS, $collapseSymJS, 72 $cur_categories; 80 global $options, $cur_categories, $subCatPosts; 73 81 extract($options); 74 82 $showHide='expand'; … … 102 110 $miscposts.=$posttext; 103 111 $miscposts.=" </ul></li>\n"; 112 if ($theID!='' && !$subCatPosts[$theID]) { 113 $subCatPosts[$theID] = $posttext; 114 } 104 115 return($miscposts); 105 116 } … … 126 137 * add option to display number of comments 127 138 */ 128 function getSubPosts($posts, $cat2, $subCatPosts, $showPosts) {139 function getSubPosts($posts, $cat2,$showPosts, $theID) { 129 140 /* returns all the posts for a given category */ 130 global $postsToExclude, $options, $thisPost ;141 global $postsToExclude, $options, $thisPost, $subCatPosts; 131 142 extract($options); 132 143 $posttext2=''; … … 142 153 continue; 143 154 if (!in_array($post2->ID, $postsToExclude)) { 144 array_push($subCatPosts, $post2->ID);145 155 $subCatPostCount2++; 146 156 if (!$showPosts) { … … 170 180 } 171 181 } 172 $posttext2.= "<li class='collapsing categories item'><a $self 173 href='".get_permalink($post2).182 $posttext2.= "<li class='collapsing categories item'><a $self " . 183 "href='".get_permalink($post2). 174 184 "' title='$title_text'>$linktext</a></li>\n"; 175 185 } 176 186 } 187 } 188 if ($theID!='' && !$subCatPosts[$theID]) { 189 $subCatPosts[$theID] = $posttext2; 177 190 } 178 191 return array($subCatPostCount2, $posttext2); … … 203 216 $postself=''; 204 217 extract($options); 205 $subCatPosts=array();206 218 $link2=''; 207 219 if ($depth==0) { … … 218 230 $self=""; 219 231 } 232 list($subCatPostCount2, $posttext2) = 233 getSubPosts($postsInCat[$cat2->term_id],$cat2, $showPosts, $theID); 220 234 if ($cat->term_id==$cat2->parent) { 221 $foo.='hallo'; 222 list($subCatPostCount2, $posttext2) = 223 getSubPosts($postsInCat[$cat2->term_id],$cat2, $subCatPosts, 224 $showPosts); 235 $theID='collapsCat-' . $cat2->term_id . "-$number"; 225 236 $subCatPostCount+=$subCatPostCount2; 226 237 $subCatPostCounts[$depth]=$subCatPostCount2; 227 238 $expanded='none'; 228 $theID='collapsCat-' . $cat2->term_id . "-$number";229 239 if (in_array($cat2->name, $autoExpand) || 230 240 in_array($cat2->slug, $autoExpand) || … … 280 290 } 281 291 } else { 282 list ($subCatLink2, $subCatCount,$subCatPostCount ,$subCatPosts)=292 list ($subCatLink2, $subCatCount,$subCatPostCount)= 283 293 get_sub_cat($cat2, $categories, $parents, $posts, $subCatCount, 284 294 $subCatPostCount,$expanded, $depth); 285 295 $subCatCount=1; 286 list($subCatPostCount2, $posttext2) =287 getSubPosts($postsInCat[$cat2->term_id],$cat2, $subCatPosts,288 $showPosts);289 296 if ($subCatPostCount2<1) { 290 297 continue; … … 336 343 if (($subCatCount>0) || ($showPosts)) { 337 344 $subCatLinks.="\n<ul id='$theID' style=\"display:$expanded\">\n"; 345 if ($expanded!='block') 346 $posttext2=''; 338 347 if ($subCatCount>0 && $posttext2!='' && $addMisc) { 339 348 $subCatLinks.=miscPosts($cat2,$catlink,$subCatPostCount2, … … 355 364 //echo $subCatLinks; 356 365 // $subCatLinks.='<br />'; 357 return(array($subCatLinks,$subCatCount,$subCatPostCount ,$subCatPosts));366 return(array($subCatLinks,$subCatCount,$subCatPostCount)); 358 367 //return(array($foo,$subCatLinks)); 359 368 } … … 541 550 /* returns a list of categories, and optionally subcategories and posts, 542 551 which can be collapsed or expanded with javascript */ 543 global $expandSym,$collapseSym,$expandSymJS, $collapseSymJS, 544 $wpdb,$options,$wp_query, $autoExpand, $postsToExclude, 552 global $wpdb,$options,$wp_query, $autoExpand, $postsToExclude, $subCatPosts, 545 553 $cur_categories, $thisPost, $wp_rewrite, $catlink, $postsInCat; 546 554 extract($options); … … 562 570 563 571 foreach( $categories as $cat ) { 572 $theID='collapsCat-' . $cat->term_id . "-$number"; 564 573 if ($inExclude=='include' && !empty($includeCatArray)) { 565 574 if (!in_array($cat->term_id, $includeCatArray) && … … 581 590 $subCatCount=0; 582 591 $subCatPostCounts=array(); 583 list ($subCatLinks, $subCatCount,$subCatPostCount , $subCatPosts)=592 list ($subCatLinks, $subCatCount,$subCatPostCount)= 584 593 get_sub_cat($cat, $categories, $parents, $posts, 585 594 $subCatCount,$subCatPostCount,$expanded,0); 586 list($subCatPostCount2, $posttext2) = 587 getSubPosts($postsInCat[$cat->term_id],$cat, $subCatPosts, $showPosts); 595 //list($subCatPostCount2, $posttext2) = 596 //getSubPosts($postsInCat[$cat->term_id],$cat, $showPosts, $theID); 597 // Get post info 598 $posttext=''; 599 if( ! empty($postsInCat[$cat->term_id]) ) { 600 list ($subCatPostCount, $posttext) = getSubPosts($posts, $cat, 601 $showPosts, $theID); 602 } 588 603 589 $theCount=$subCatPostCount2+$subCatPostCount; 604 //$theCount=$subCatPostCount2+$subCatPostCount; 605 $theCount= $subCatPostCount; 606 590 607 if ($theCount>0) { 591 608 $expanded='none'; 592 $theID='collapsCat-' . $cat->term_id . "-$number";593 609 if (in_array($cat->name, $autoExpand) || 594 610 in_array($cat->slug, $autoExpand) || … … 608 624 "<span class='collapsing categories $showHide' ". 609 625 "onclick='expandCollapse(event, \"$expandSymJS\"," . 610 "\"$collapseSymJS\", $animate, \"collapsing categories\"); return false'>".611 " <span class='sym'>$symbol</span>";626 "\"$collapseSymJS\", $animate, \"collapsing categories\");" . 627 " return false'><span class='sym'>$symbol</span>"; 612 628 } else { 613 629 $span = " <li class='collapsing categories item'>"; … … 639 655 } 640 656 } 641 // Now print out the post info642 $posttext='';643 if( ! empty($postsInCat[$cat->term_id]) ) {644 list ($subCatPostCount, $posttext) = getSubPosts($posts, $cat,645 $subCatPosts, $showPosts);646 }647 657 if( $showPostCount=='yes') { 648 658 $link .= ' (' . $theCount.')'; … … 662 672 if ($showPosts) { 663 673 if ($subCatPostCount>0 && $subCatLinks!='' && $addMisc) { 664 $posttext = (miscPosts($cat,$catlink,$subCatPostCount 2,$posttext));674 $posttext = (miscPosts($cat,$catlink,$subCatPostCount,$posttext)); 665 675 } 666 676 } … … 670 680 $text = $subCatLinks . $posttext; 671 681 } 682 if ($theID!='') { 683 $subCatPosts[$theID] = $text; 684 } 685 /* we only actually add the posts if it is expanded. Otherwise we add 686 the posts dynamically to the dom from a javascript array 687 However, we can't have an empty ul, so we create one emtpy li here */ 688 if ($expanded!='block') { 689 $posttext='<li></li>'; 690 } 691 if ($postsBeforeCats) { 692 $text =$posttext . $subCatLinks; 693 } else { 694 $text = $subCatLinks . $posttext; 695 } 672 696 $collapsCatText .= $text; 673 697 if ($showTopLevel) {
Note: See TracChangeset
for help on using the changeset viewer.