Revision [6261]

This is an old revision of PageAndCategoryDivisionInACategory made by NilsLindenberg on 2005-02-23 11:49:21.

 

Division between Pages and categories in a Category


I haven't found the code for JWs better category-action, see WikkaBetaFeatures for what I mean, and therefore have just made some little changes to the 1.1.6.0 code:

If you use the following code to replace your actions/category.php, Categories are listed seperate from pages, and the first ones without the "Category" in front.

here's the code:
  1. <?php
  2. if ($cattag = $_REQUEST["wakka"])
  3. {
  4.     $str ="";
  5.     $categorystr="";
  6.     if (!isset($col)) $col=1;
  7.     if (!isset($compact)) $compact=0;
  8.     if (!isset($page)) $page=$this->getPageTag();
  9.     if ($page=="/") $page="CategoryCategory";
  10.  
  11. //  $page= preg_replace( "/(\w+)\s(\w+)/", "$1$2",$page);
  12.     if (isset($class))
  13.     {
  14.         $class="class=\"$class\"";
  15.     } else
  16.     {
  17.         $class="";
  18.     }
  19.     if (!$page) {$page=$cattag;}
  20.  
  21.     if ($this->CheckMySQLVersion(4,0,1))
  22.     {
  23.             $results = $this->FullCategoryTextSearch($page);
  24.     }
  25.     else
  26.     {
  27.             $results = $this->FullTextSearch($page);
  28.     }
  29.  
  30.     if ($results)
  31.     {
  32.         if (!$compact) $str .= ' to ' . $page . ': <br /><br /><table '.$class.' width="100%"><tr>';
  33.         else $str .= '<div '.$class.'><ul>';
  34.         $categorystr .= ' pages belong to ' . $page . ': <br /><br /><div '.$class.'><ul>';
  35.        
  36.         $count = 0;
  37.         $pagecount = 0;
  38.         $categorycount = 0;    
  39.    
  40.         $list = array();
  41.        
  42.         foreach ($results as $i => $cpage) if($cpage['tag'] != $page) { array_push($list,$cpage['tag']);}
  43.         sort($list);
  44.         while (list($key, $val) = each($list))
  45.         {
  46.             if (eregi("^Category", $val))   // do we have a category?? 
  47.             {
  48.                 $categorystr .= '<li>'.$this->Format('[['.$val.' '.preg_replace( "/Category/", "",$val).']]').'</li>';
  49.                 $categorycount++;
  50.             }
  51.             else                // no, must be a page then!
  52.             {
  53.                 if ($count == $col & !$compact)  { $str .= "</tr><tr>"; $count=0; }
  54.                 if (!$compact) $str .= '<td>'.$this->Format('[['.$val.']]').'</td>';
  55.                 else $str .= '<li>'.$this->Format('[['.$val.' '.preg_replace( "/Category/", "",$val).']]').'</li>';
  56.                 $count++;
  57.                 $pagecount++;
  58.             }
  59.         }
  60.         if ($pagecount == 1) $str = 'The following page belongs'.$str;
  61.         else $str = 'The following '.$pagecount.' pages belong'.$str;
  62.  
  63.         if ($categorycount == 1) $categorystr = 'The following category belongs'.$categorystr;
  64.         else $categorystr = 'The following '.$categorycount.' categories belong'.$categorystr;
  65.  
  66.         if (!$compact)  $str .= '</tr></table>'; else $str .= '</ul></div>';
  67.         $categorystr .= '</ul></div>';
  68.     }
  69.     else $str .= 'Sorry, no items found for ' .$page .'.';
  70.    
  71.     if ($categorycount)
  72.     {
  73.         print ($categorystr);
  74.         echo '<br /><br />';
  75.     }
  76.     if (pagecount) print($str);
  77.     echo '<br /><br />';   
  78. }
  79. ?>
There are 22 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki