Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Categories

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
Vito133
Smarty n00b


Joined: 01 Dec 2004
Posts: 3

PostPosted: Wed Dec 01, 2004 9:22 am    Post subject: Categories Reply with quote

Code:
<ul>
   {section name=list loop=$category_id}
   {if $category_parent[list]==0}
      <br/>
      <li title="{$category_name[list]}" lang="en">{$category_name[list]}</li>
         <ul>
            {section name="nr" loop=$parent_total}
               {if $catparent_parent[nr]==$category_id[list]}
                  <li>
                     {$catparent_name[nr]}
                  </li>
               {/if}
            {/section}
         </ul>
   {/if}
   {/section}
<ul/>


What can I do to create n sub...-subcategories?

-AAAA
----BBBB
-------CCCC
-MMMM
----NNNN
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Dec 01, 2004 3:26 pm    Post subject: Reply with quote

http://www.phpinsider.com/smarty-forum/viewtopic.php?t=291
Back to top
View user's profile Send private message
Vito133
Smarty n00b


Joined: 01 Dec 2004
Posts: 3

PostPosted: Thu Dec 02, 2004 8:49 pm    Post subject: Reply with quote

How can i use that plugin with a DB. I canīt run the plugin.

This is my final script but is not endless

Code:
<ul>
   {section name=nr loop=$category_id}
   {if $category_parent[nr]==0}
      <br/>
      <li title="{$category_name[list]}" lang="en">{$category_name[nr]}</li>
         {*$category_description[nr]|nl2br*}
         {section name=nr1 loop=$category_total}
               {if $category_parent[nr1]==$category_id[nr]}
                  <ul>
                     <li>
                        {$category_name[nr1]}
                     </li>
               {section name=nr2 loop=$category_total}
               {if $category_parent[nr2]==$category_id[nr1]}
                  <ul>
                     <li>
                        {$category_name[nr2]}
                     </li>
               {section name=nr3 loop=$category_total}
               {if $category_parent[nr3]==$category_id[nr2]}
                  <ul>
                     <li>
                        {$category_name[nr3]}
                     </li>
                  </ul>
               {/if}
               {/section}
                  </ul>
               {/if}
               {/section}
                  </ul>
               {/if}
         {/section}
   {/if}
   {/section}
<ul/>


Thanks
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Dec 03, 2004 12:06 am    Post subject: Reply with quote

hmm. I don't think I follow you very well -- you mention a db? Your example is not using the plugin either -- what do you mean it didn't run for you? Was there an error? (Note: you want the plugin listed on page 4 of that thread)

Here is an example which you may be of some help. I don't like the {defun}/{fun} names so in my implentation they are {macro}/{macro_call}. The following is a very basic implementation of the SuckerFishMenu technique. The data format is an associative array where the key is the title and the value is the url. If the url is actually an array, that is considered a sub-menu.

[php:1:a24123af34]<?php
$menu_data = array(
'Smarty' => array(
'home' => 'http://smarty.php.net/'
, 'SmartyMenu' => 'http://www.phpinsider.com/php/code/SmartyMenu/'
)
, 'htmldog' => array(
'dropdowns' => 'http://www.htmldog.com/articles/suckerfish/dropdowns/')
);

$smarty->assign('menu_data', $menu_data);
$smarty->display('SuckerFishMenu.tpl');
?>[/php:1:a24123af34]

SuckerFishMenu.tpl
Code:

{**
 * MACRO - SuckerFishMenu
 * Author: boots
 *
 * Inspired by SmartyMenu Addon for Smarty by Monte Ohrt
 *   http://www.phpinsider.com/php/code/SmartyMenu/
 *
 * which is itself based on the implementation by Patrick Griffiths and Dan Webb
 *   http://www.htmldog.com/articles/suckerfish/dropdowns/
 **}

{macro name="SuckerFishMenu" data=$menu}
{foreach from=$data key=title item=url}
    {if is_array($url)}
        <li>{$title}
            <ul>
                {macro_call name="SuckerFishMenu" data=$url}
            </ul>
        </li>
    {else}
        <li><a href="{$url}">{$title}</a></li>
    {/if}
{/foreach}
{/macro}

{* now that the macro is defined, call it wherever and whenever you need it *}
<div id="primaryNav"><ul>{macro_call name="SuckerFishMenu" data=$menu_data id="nav"}</ul></div>
Back to top
View user's profile Send private message
Vito133
Smarty n00b


Joined: 01 Dec 2004
Posts: 3

PostPosted: Wed Dec 08, 2004 3:19 pm    Post subject: Reply with quote

Hi, the case is iīm using a DB.
If the category_parent=0, is the main category and if the category_parent!=0, is a parent category. Next, i need to know if the category_parent = category_id of each main category, that endless times(thats my problem). I need and othere solution to create that tree n times.

Code:
CREATE table shpx_categories (
  category_id int(4) NOT NULL auto_increment,
  category_name varchar(55) NOT NULL default '',
  category_description text NOT NULL,
  category_parent int NOT NULL default '0',
  category_date datetime default NULL,
  PRIMARY KEY  (category_id),
  UNIQUE KEY cat_name (category_name),
) TYPE=MyISAM AUTO_INCREMENT=3 ;



Code:
$query = "select * from shpx_categories order by category_name asc";
$res = $this->query ($query);
$i=0;
$cat_total = $this->num_rows ($res);
if ($res) {
while ($template_args = $this->fetch_array ($res)) {
$smarty->append ($template_args);
if ($cat_total > 0) {
$i++;
$smarty->assign_by_ref ('category_total',$i);
}
}
}


That is my code for the .tpl, but isnīt the right one.
Code:
<ul>
   {section name=nr loop=$category_id}
   {if $category_parent[nr]==0}
      <br/>
      <li title="{$category_name[list]}" lang="en">{$category_name[nr]}</li>
         {*$category_description[nr]|nl2br*}
         {section name=nr1 loop=$category_total}
               {if $category_parent[nr1]==$category_id[nr]}
                  <ul>
                     <li>
                        {$category_name[nr1]}
                     </li>
               {section name=nr2 loop=$category_total}
               {if $category_parent[nr2]==$category_id[nr1]}
                  <ul>
                     <li>
                        {$category_name[nr2]}
                     </li>
               {section name=nr3 loop=$category_total}
               {if $category_parent[nr3]==$category_id[nr2]}
                  <ul>
                     <li>
                        {$category_name[nr3]}
                     </li>
                  </ul>
               {/if}
               {/section}
                  </ul>
               {/if}
               {/section}
                  </ul>
               {/if}
         {/section}
   {/if}
   {/section}
<ul/>


Thanks and sorry for my english.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP