Go Back   Pligg Forum > Pligg Help > Pligg Tutorials
Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 09-19-2007, 11:46 AM
AnAlienHolakres3's Avatar
AnAlienHolakres3 AnAlienHolakres3 is offline
Send a message via ICQ to AnAlienHolakres3
Pligg Developer
 
Join Date: Jul 2007
Location: Prague
Posts: 117
Downloads: 24
Uploads: 1
Thanks: 7
Thanked 111 Times in 40 Posts
Sidebar Categories Enh. AddOn: v.0.2

This version provides more functionality:
1) if you select subcategory then subcategories of specific root category are shown even when you reload the page
2) every selected category/subcategory is highlighted


Steps to do:
1) Open search.php in your libs folder.
Find following code:
PHP Code:
       //should we filter to just this category?
        
if(isset($this->category))
        {
            
//$catId = $db->get_var("SELECT category_id from " . table_categories . " where category_name = '" . $this->category . "';");
            
$catId get_category_id($this->category);
            if(isset(
$catId)){
                
$child_cats ''
Then Add this code after it:
PHP Code:
                //===========categories ADDON-AnALienHolakres3                                  
                   
$selected_root_id $db->get_var("SELECT category_parent FROM " table_categories " WHERE `category_id` = " .  $catId); 
                    
$main_smarty->assign('selected_root_id',$selected_root_id);   
                    
$main_smarty->assign('selected_cat_id',$catId);      
                
//============addon END 
2) If you have Pligg version 9.7 replace all code in categories.tpl (templates/template/sidebar modules folder) with:
PHP Code:
    {php}  

  
       function 
set_root_smart() {
       global 
$main_smarty;
        
$root_id=Array();
        
$array tree_to_array(0table_categories);
            
//get array of categories
            
foreach ($array as $cat) {
                
$cat_id[]=$cat['auto_id'];
                
            }     
           
//get array of subcategories 
            
foreach ($array as $subcat) {              
                
$cat_parent[]=$subcat['parent'];
                
            }   
             
//compare and set root ids  
             
foreach ($cat_id as $category_id){
              foreach (
$cat_parent as $category_parent){
                if (
$category_id && $category_parent) {      
                 if (
$category_id==$category_parent) {      
                   if(!
in_array($category_id,$root_id)) {
                   
$root_id[] = $category_id;
                
                 }
               }
             }        
           }              
       }
            
       
$main_smarty->assign('root_id',$root_id);
       return 
$root_id;
     }
     
     
set_root_smart(); 
     
   {/
php}   
   
   
<
div class="tlb">
    {
php}
        echo 
"<span><a onclick=\"new Effect.toggle('cats','blind', {queue: 'end'}); \"> <img src=\"".my_pligg_base."/templates/".The_Template."/images/expand.png\"></a></span>";
    {/
php}
    <
a href="#">{#PLIGG_Visual_Category_Title#}</a>
</div>

<
div id="cats" style="padding-bottom:1px">
    <
ul class="nav-secondary">  
        {
section name=thecat loop=$cat_array start=1}

            {if 
$cat_array[thecat].spacercount lt $lastspacer}{$cat_array[thecat].spacerdiff|repeat_count:'</ul>''</div>'}{/if}
            {if 
$cat_array[thecat].spacercount gt $lastspacer}<ul>{/if}

            <
a href="{$URL_rsscategory, $cat_array[thecat].auto_id}" target="_blank" style="border:none;">      
            <
img src="{$my_pligg_base}/templates/{$the_template}/images/rss.gif" border="0" style="float:right;padding-right:7px;"></a>
                    
                        
                        {
section name=root2 loop=$root_id start=0}
                        {if 
$cat_array[thecat].auto_id eq $root_id[root2]}   
                        
                                {if 
$root_id[root2neq $selected_root_id}  
                       <
img id="picroot{$cat_array[thecat].auto_id}"style="float:right;padding-right:7px;margin-top:1px;width:18px;height:14px" src="../templates/yget/images/scroll_down.ico" width="18" height="14" 
                        
onmouseover="this.src='../templates/yget/images/scroll_down_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_down.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='';document.getElementById('picrootU{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'"
                       
                       <
img id="picrootU{$cat_array[thecat].auto_id}"style="float:right;padding-right:7px;margin-top:1px;display:none;width:18px;height:14px" src="../templates/yget/images/scroll_up.ico" width="18" height="14" 
                        
onmouseover="this.src='../templates/yget/images/scroll_up_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_up.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='none';document.getElementById('picroot{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'"
                                {else}
                                 <
img id="picroot{$cat_array[thecat].auto_id}"style="display:none;float:right;padding-right:7px;margin-top:1px;width:18px;height:14px" src="../templates/yget/images/scroll_down.ico" width="18" height="14" 
                                 
onmouseover="this.src='../templates/yget/images/scroll_down_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_down.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='';document.getElementById('picrootU{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'"
                       
                                <
img id="picrootU{$cat_array[thecat].auto_id}"style="float:right;padding-right:7px;margin-top:1px;width:18px;height:14px" src="../templates/yget/images/scroll_up.ico" width="18" height="14" 
                                
onmouseover="this.src='../templates/yget/images/scroll_up_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_up.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='none';document.getElementById('picroot{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'">           
                                  
                                {/if}
                          
                          
                          {/if}                                     
                          {/
section}   
                        
                            
            
                    {if 
$pagename eq "published"
                       
                        {
section name=root loop=$root_id start=0}
                        {if 
$cat_array[thecat].auto_id eq $root_id[root]}                                                                                                
                        <
a href="{$URL_maincategory, $cat_array[thecat].safename}" style={if $root_id[rooteq $selected_cat_id}"font-weight:bold;padding-bottom:5px;color:#0033e3"{else}"padding-bottom:5px;"{/if}>{$cat_array[thecat].name}</a
                        <
div id="subcat{$cat_array[thecat].auto_id}" {if $root_id[rootneq $selected_root_idstyle="display:none"{/if}>   
                        {
assign var=root_category value=$cat_array[thecat].auto_id}      
                        {/if}                       
                        {/
section}  
                        
             
                        {if 
$cat_array[thecat].auto_id neq $root_category}  
                         <
a href="{$URL_maincategory, $cat_array[thecat].safename}" style={if $cat_array[thecat].auto_id eq $selected_cat_id}"font-weight:bold;padding-bottom:5px;color:#0033e3"{else}"padding-bottom:5px;"{/if}>{$cat_array[thecat].name}</a>  
                         {/if}
                      
                     
                        {else}  
                        
                        {
section name=root loop=$root_id start=0}
                        {if 
$cat_array[thecat].auto_id eq $root_id[root]}                                                                                                
                        <
a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style={if $root_id[rooteq $selected_cat_id}"font-weight:bold;padding-bottom:5px;color:#0033e3"{else}"padding-bottom:5px;"{/if}>{$cat_array[thecat].name}</a
                        <
div id="subcat{$cat_array[thecat].auto_id}" {if $root_id[rootneq $selected_root_id}style="display:none"{/if}>   
                        {
assign var=root_category value=$cat_array[thecat].auto_id}      
                        {/if}                       
                        {/
section}  
                        
             
                        {if 
$cat_array[thecat].auto_id neq $root_category}  
                         <
a href="{$URL_queuedcategory, $cat_array[thecat].safename}" style={if $cat_array[thecat].auto_id  eq $selected_cat_id}"font-weight:bold;padding-bottom:5px;color:#0033e3"{else}"padding-bottom:5px;"{/if}>{$cat_array[thecat].name}</a>  
                         {/if}
                        
                  
                        {/if}
               
                                                   
                    
                    
                    
                    </
li>      
            
            {
assign var=lastspacer value=$cat_array[thecat].spacercount}
        {/
section}
    </
ul>
</
div
If you use latest Pligg version (0.98) please read next post.
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.org
Reply With Quote
Sponsored Links
Check out the New Modules at the Pligg Pro Shop.
  #12 (permalink)  
Old 09-19-2007, 11:48 AM
AnAlienHolakres3's Avatar
AnAlienHolakres3 AnAlienHolakres3 is offline
Send a message via ICQ to AnAlienHolakres3
Pligg Developer
 
Join Date: Jul 2007
Location: Prague
Posts: 117
Downloads: 24
Uploads: 1
Thanks: 7
Thanked 111 Times in 40 Posts
Sidebar Categories Enh. AddOn: v.0.2 for Pligg v0.98

f you use Pligg Version 9.8 there is UPDATED and FIXED code (yeah, I have discovered the problem so if somebody could test it and give me some feedback I would appreciate that:).
PHP Code:
{php}  
//********************************************************************************************
// This file is for VERSION 0.98 ONLY!. (categories.tpl)
//Customized by AnAlienHolakres3 for Pligg Comunity. No warranty,Free of charge
// If you like it you can always make your own tut for the rest of us
//********************************************************************************************
       
function set_root_smart() {
       global 
$main_smarty;
        
$root_id=Array();
        
$array tree_to_array(0table_categories);
            
//get array of categories
            
foreach ($array as $cat) {
                
$cat_id[]=$cat['auto_id'];
                
            }     
           
//get array of subcategories 
            
foreach ($array as $subcat) {              
                
$cat_parent[]=$subcat['parent'];
                
            }   
             
//compare and set root ids  
             
foreach ($cat_id as $category_id){
              foreach (
$cat_parent as $category_parent){
                if (
$category_id && $category_parent) {      
                 if (
$category_id==$category_parent) {      
                   if(!
in_array($category_id,$root_id)) {
                   
$root_id[] = $category_id;
                
                 }
               }
             }        
           }              
       }
            
       
$main_smarty->assign('root_id',$root_id);
       return 
$root_id;
     }
     
     
set_root_smart(); 
     
   {/
php}  
<
div class="tlb">
    {
php}
        echo 
"<span><a onclick=\"new Effect.toggle('cats','blind', {queue: 'end'}); \"> <img src=\"".my_pligg_base."/templates/".The_Template."/images/expand.png\" alt=\"expand\" /></a></span>";
    {/
php}
    <
a href="#">{#PLIGG_Visual_Category_Title#}</a>
</div>

<
div id="cats" style="padding-bottom:1px">
    <
ul id="nav-secondary">
        <
li>
            {
section name=thecat loop=$cat_array start=1}
                {if 
$lastspacer eq ""}
               
                    {
assign var=lastspacer value=$cat_array[thecat].spacercount}
                {/if}

                {if 
$cat_array[thecat].spacercount lt $lastspacer}{$cat_array[thecat].spacerdiff|repeat_count:'</li></ul></div>'}{/if}
                {if 
$cat_array[thecat].spacercount gt $lastspacer}<ul style="padding-left:12px"><li>{/if}

                <
a href="{$URL_rsscategory, $cat_array[thecat].auto_id}" target="_blank" style="border:none;">      
                <
img src="{$my_pligg_base}/templates/{$the_template}/images/rss.gif" border="0" style="float:right;padding-right:10px;" alt="RSS" /></a>
                
                        {
section name=root2 loop=$root_id start=0}
                        {if 
$cat_array[thecat].auto_id eq $root_id[root2]}   
                          
                                        {if 
$root_id[root2neq $selected_root_id}  
                                          <
img id="picroot{$cat_array[thecat].auto_id}"style="float:right;padding-right:7px;margin-top:1px;width:18px;height:14px" src="../templates/yget/images/scroll_down.ico" width="18" height="14" 
                                             
onmouseover="this.src='../templates/yget/images/scroll_down_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_down.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='';document.getElementById('picrootU{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'"
                       
                                           <
img id="picrootU{$cat_array[thecat].auto_id}"style="float:right;padding-right:7px;margin-top:1px;display:none;width:18px;height:14px" src="../templates/yget/images/scroll_up.ico" width="18" height="14" 
                                                
onmouseover="this.src='../templates/yget/images/scroll_up_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_up.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='none';document.getElementById('picroot{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'"
                                    {else}
                                           <
img id="picroot{$cat_array[thecat].auto_id}"style="display:none;float:right;padding-right:7px;margin-top:1px;width:18px;height:14px" src="../templates/yget/images/scroll_down.ico" width="18" height="14" 
                                                
onmouseover="this.src='../templates/yget/images/scroll_down_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_down.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='';document.getElementById('picrootU{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'"
                       
                                         <
img id="picrootU{$cat_array[thecat].auto_id}"style="float:right;padding-right:7px;margin-top:1px;width:18px;height:14px" src="../templates/yget/images/scroll_up.ico" width="18" height="14" 
                                              
onmouseover="this.src='../templates/yget/images/scroll_up_hover.ico';this.width='18';this.height='14'" onmouseout="this.src='../templates/yget/images/scroll_up.ico';this.width='18';this.height='14'" onmousedown="document.getElementById('subcat{$cat_array[thecat].auto_id}').style.display='none';document.getElementById('picroot{$cat_array[thecat].auto_id}').style.display='';this.style.display='none'">           
                                  
                                      {/if}
                        
                        
                          {/if}                                     
                          {/
section}  
                
                
        
                {if 
$pagename eq "published"}
                
                    {
section name=root loop=$root_id start=0}
                        {if 
$cat_array[thecat].auto_id eq $root_id[root]}                                                                                                
                        <
a href="{$URL_maincategory, $cat_array[thecat].safename}" style={if $root_id[rooteq $selected_cat_id}"font-weight:bold;padding-bottom:5px;color:#0033e3"{else}"padding-bottom:5px;"{/if}>{$cat_array[thecat].name}</a
                        <
div id="subcat{$cat_array[thecat].auto_id}" {if $root_id[rootneq $selected_root_idstyle="display:none"{/if}>   
                        {
assign var=root_category value=$cat_array[thecat].auto_id}      
                        {/if}