Pagina 1 di 1

CATEGORIE IN HEADER - modifica in php

Inviato: 10/01/2008, 23:42
da lucky_it
Salve a tutti...chiedo un "piccolo" ma ENORME aiuto a chi mastica un pò di php e riesce a modificare la pagina che allego.

Si tratta di una pagina che mi fa visualizzare le categorie in orizzontale sotto l'header.

cosa fa:
__________________________________________________
catA catB catC
__________________________________________________

se ad esempio seleziono la categoria B,vengono visualizzate le sottocategorie in questo modo:

__________________________________________________
catA catB sottocatB1 sottocatB2 sottocatB3 catC
__________________________________________________

quello che servirebbe sarebbe che nella riga sopra restino solo le categorie madri ed in una riga sottostante si selezioni la categoria con le proprie sottocategorie

ad esempio:
__________________________________________________
catA catB catC

catB sottocatB1 sottocatB2 sottocatB3
__________________________________________________

Spero di essere stato abbastanza chiaro o fatemi sapere.
Credo si tratti di una modifica abbastanza veloce per chi mastica php.

:-)) Un grazie infinito in anticipo a chiunque colga la sfida



www.matissevenezia.com

Codice: Seleziona tutto

<?php
/*
  $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License

  changed August 2003, by Nils Petersson
  contribution "Category Box Enhancement", version 1.1

*/

  function tep_show_category($counter) {

// BoF - Contribution Category Box Enhancement 1.1
    global $tree, $categories_string, $cPath_array, $cat_name;

    for ($i=0; $i<$tree[$counter]['level']; $i++) {
      $categories_string .= "  ";
    }
    $cPath_new = 'cPath=' . $tree[$counter]['path'];
    if (isset($cPath_array) && in_array($counter, $cPath_array) && $cat_name == $tree[$counter]['name']) { //Link nicht anklickbar, wenn angewählt
             $categories_string .= '<a href="';
             $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';																	 	 //Link nicht anklickbar, wenn angewählt
    } else {						 																					 //Link nicht anklickbar, wenn angewählt
    $categories_string .= '<a href="';
    $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
    }									 																						 //Link nicht anklickbar, wenn angewählt
    if (tep_has_category_subcategories($counter)) {
      $categories_string .= tep_image(DIR_WS_IMAGES . 'pointer_blue.gif', '');
    }
    else {
      $categories_string .= tep_image(DIR_WS_IMAGES . 'pointer_blue_light.gif', '');
    }

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $categories_string .= '<b>';
    }

    if ($cat_name == $tree[$counter]['name']) {
      $categories_string .= '<span class="errorText">';
    }

// display category name
    $categories_string .= $tree[$counter]['name'];

		if ($cat_name == $tree[$counter]['name']) {
			$categories_string .= '</span>';
    }

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $categories_string .= '</b>';
    }
// 	EoF Category Box Enhancement

    $categories_string .= '</a>';

    if (SHOW_COUNTS == 'true') {
      $products_in_category = tep_count_products_in_category($counter);
      if ($products_in_category > 0) {
        $categories_string .= ' (' . $products_in_category . ')';
      }
    }

    $categories_string .= '  ';

    if ($tree[$counter]['next_id'] != false) {
      tep_show_category($tree[$counter]['next_id']);
    }
  }
?>
<!-- categories //--><table width="100%" border="0"><tr>

          <td>
<?php

// BoF - Contribution Category Box Enhancement 1.1
 if (isset($cPath_array)) {
		for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
				$categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
				if (tep_db_num_rows($categories_query) > 0)
				$categories = tep_db_fetch_array($categories_query);
		}
	$cat_name = $categories['categories_name'];
	}
// EoF Category Box Enhancement
// display category name

  $info_box_contents = array();
  $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

  new infoBoxHeading($info_box_contents, true, false);

  $categories_string = '';
  $tree = array();

  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  while ($categories = tep_db_fetch_array($categories_query))  {
    $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                'parent' => $categories['parent_id'],
                                                'level' => 0,
                                                'path' => $categories['categories_id'],
                                                'next_id' => false);

    if (isset($parent_id)) {
      $tree[$parent_id]['next_id'] = $categories['categories_id'];
    }

    $parent_id = $categories['categories_id'];

    if (!isset($first_element)) {
      $first_element = $categories['categories_id'];
    }
  }

  //------------------------
  if (tep_not_null($cPath)) {
    $new_path = '';
    reset($cPath_array);
    while (list($key, $value) = each($cPath_array)) {
      unset($parent_id);
      unset($first_id);
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
      if (tep_db_num_rows($categories_query)) {
        $new_path .= $value;
        while ($row = tep_db_fetch_array($categories_query)) {
          $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                               'parent' => $row['parent_id'],
                                               'level' => $key+1,
                                               'path' => $new_path . '_' . $row['categories_id'],
                                               'next_id' => false);

          if (isset($parent_id)) {
            $tree[$parent_id]['next_id'] = $row['categories_id'];
          }

          $parent_id = $row['categories_id'];

          if (!isset($first_id)) {
            $first_id = $row['categories_id'];
          }

          $last_id = $row['categories_id'];
        }
        $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
        $tree[$value]['next_id'] = $first_id;
        $new_path .= '_';
      } else {
        break;
      }
    }
  }
  tep_show_category($first_element);

  $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);

// if ( (basename($PHP_SELF) != FILENAME_SPECIALS)) {
//$info_box_contents[] = array('align' => 'right',
 //                              'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '">' . SPECIAL_PRODUCTS_LINK . '</a></b></font>');
// }else{
// $info_box_contents[] = array('align' => 'right',
//                               'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '">' . BOX_INFORMATION_SPECIALS . '</a></b></font>');
 // }
 //if ( (basename($PHP_SELF) != FILENAME_PRODUCTS_NEW)) {
//$info_box_contents[] = array('align' => 'right',
 //                              'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL') . '">' . NEW_PRODUCTS_LINK . '</a></b></font>');
// }else{
// $info_box_contents[] = array('align' => 'right',
//                               'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL') . '">' . ALL_PRODUCTS_LINK .'</a></b></font>');
 // }
  function tep_get_paths($categories_array = '', $parent_id = '0', $indent = '', $path='') {
    global $languages_id;

    if (!is_array($categories_array)) $categories_array = array();

    $categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
    while ($categories = tep_db_fetch_array($categories_query)) {
      if ($parent_id=='0'){
	$categories_array[] = array('id' => $categories['categories_id'],
                                      'text' => $indent . $categories['categories_name']);
      }
      else{
	$categories_array[] = array('id' => $path . $parent_id . '_' .$categories['categories_id'],
        	                          'text' => $indent . $categories['categories_name']);
      }

      if ($categories['categories_id'] != $parent_id) {
	$this_path=$path;
	if ($parent_id != '0')
	  $this_path = $path . $parent_id . '_';
        $categories_array = tep_get_paths($categories_array, $categories['categories_id'], $indent . ' ', $this_path);
      }
    }

    return $categories_array;
  }
 
?>


 
<?php

 // $info_box_contents[] = array('form' => '<form action="' . tep_href_link(FILENAME_DEFAULT) . '" method="get">' . tep_hide_session_id(),
 //                              'align' => 'right',
 //                              'text'  => '<font size=-2><b>' . BOX_DROPDOWN_MENUS . '<br>' . tep_draw_pull_down_menu('cPath', tep_get_paths(array(array('id' => '</b></font>', 'text' => PULL_DOWN_DEFAULT))), $cPath, 'onchange="this.form.submit();" style="width: 200"')
 //                            );
  new infoBox($info_box_contents);
?>

            </td>

      </tr></table>
<!-- categories_eof //-->
[/code]

Inviato: 23/01/2008, 15:45
da lucky_it
Ragazzi ho postato questa richiesta il 10 di gennaio ed a oggi tanti hanno letto ma nessuno mi ha aiutato eppure credo che gente che mastichi bene php ce ne sia parecchia..... ci spero ancora ;-)

GRAZIE ANTICIPATO

Inviato: 17/04/2008, 11:30
da dynamo
vai su www.html.it nella sezione javascript cercati gli script per il menu... e vedrai cosa devi fare per farlo come vuoi te...

poi è solo questione di integrazione :wink:

Inviato: 18/04/2008, 20:34
da loris_ripa
lucky_it ha scritto:Ragazzi ho postato questa richiesta il 10 di gennaio ed a oggi tanti hanno letto ma nessuno mi ha aiutato eppure credo che gente che mastichi bene php ce ne sia parecchia..... ci spero ancora ;-)

GRAZIE ANTICIPATO
Potresti farlo adattando un menu in css...guarda qui:

http://www.dynamicdrive.com/style/cssli ... ory/C1/P0/

Dovrai mettere mano al file categories.php...
:D

Inviato: 19/04/2008, 16:22
da lucky_it
GRAZIE PER LE RISPOSTE :-)

Il fatto è che non credo si tratti di dover aggiungere javascript o altre funzioni per realizzare quello che intendo io...ma solamente di alcune piccole modifiche al file che ho postato.

Il file infatti è già una contribution che serve per posizionare le categorie in orizzontale...ed infatti così appaiono.
Il problema è nelle sottocategorie.
Quello che mi servirebbe sarebbe che nella prima riga restino le categorie principali e nella seconda riga vengano mostrate le sottocategorie della categoria principale selezionata.


Spero di essere stato chiaro....
e credo si tratti solo di alcune modifiche al codice postato sopra. (o comuqnue potrei sbagliarmi ;-)

per avere un idea vedete le categorie (denominate collezioni) direttamente on line su
http://www.matissevenezia.com

per il momento ho solamente differenziato le categorie usando lo stampatello e le sottocategorie in testo normale...ma non risulta pulito come vorrei


GRAZIE TANTO TANTO TANTO

Inviato: 19/04/2008, 16:34
da lucky_it
aggiunta al messaggio precedente:

credo che in realtà il file da modificare sia quello che posto qui di seguito e non quello messo nel primo post.

Codice: Seleziona tutto

<?php
/*
  $Id: categories-row.php,v 1.25 2007/08/03 09:13:00 hpdl Exp $

  Chili Pepper Consulting; chilico.com; Karen Piotrowski
  for osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  function tep_show_category_row($counter) {

    global $tree, $categories_string, $cPath_array;

    $cPath_new = 'cPath=' . $counter;

    $categories_string .= '<span class="headerNavigation">';

    $categories_string .= '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

    $categories_string .= $tree[$counter]['name'];

    $categories_string .= '</a>';

    if (SHOW_COUNTS == 'true') {
      $products_in_category = tep_count_products_in_category($counter);
      if ($products_in_category > 0) {
        $categories_string .= ' (' . $products_in_category . ')';
      }
    }

    $categories_string .= '</span>';

    if ($tree[$counter]['next_id'] != false) {
      tep_show_category_row($tree[$counter]['next_id']);
    }
		
  }
?>

<!-- categories //-->
<?php

  $categories_string = '';
  $tree = array();

  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  while ($categories = tep_db_fetch_array($categories_query))  {
    $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                'parent' => $categories['parent_id'],
                                                'level' => 0,
                                                'path' => $categories['categories_id'],
                                                'next_id' => false);

    if (isset($parent_id)) {
      $tree[$parent_id]['next_id'] = $categories['categories_id'];
    }

    $parent_id = $categories['categories_id'];

    if (!isset($first_element)) {
      $first_element = $categories['categories_id'];
    }
  }

  tep_show_category_row($first_element); 

  echo $categories_string;

?>
<!-- categories_eof //-->

[/code]

Inviato: 19/04/2008, 17:40
da dynamo
guarda che devi rifare il menu ;)

per cui vai su html.it e cercati lo script per un menu su due righe come lo vuoi te e te lo integri :P

Inviato: 20/04/2008, 14:13
da lucky_it
Trovato l'arcano dopo tante ore passate sopra ho capito che mi basterebbe
aggiungere nel punto giusto la stringa

$categories_string.='<br>';

per fare in maniera tale che le categorie risultino tutte su una riga
e le sotto categorie sulla riga inferiore in base alla categoria selezionata


fatto sta che non trovo il punto dove inserire correttamente la stringa... un aiuto PLEASEEEEE


Ecco il codice categories.php (per le categorie in orizzontale sotto header)

Codice: Seleziona tutto

<?php
/*
  $Id: categories.php,v 1.25 2003/07/09 01:13:58 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License

  changed August 2003, by Nils Petersson
  contribution "Category Box Enhancement", version 1.1

*/

  function tep_show_category($counter) {

// BoF - Contribution Category Box Enhancement 1.1
    global $tree, $categories_string, $cPath_array, $cat_name;

    for ($i=0; $i<$tree[$counter]['level']; $i++) {
      $categories_string .= "  ";
    }
    $cPath_new = 'cPath=' . $tree[$counter]['path'];
    if (isset($cPath_array) && in_array($counter, $cPath_array) && $cat_name == $tree[$counter]['name']) { //Link nicht anklickbar, wenn angewählt
			 $categories_string .= '<a href="';
             $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';					 //Link nicht anklickbar, wenn angewählt
    } else {																							 //Link nicht anklickbar, wenn angewählt
    $categories_string .= '<a href="';
    $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';
    }									 																 //Link nicht anklickbar, wenn angewählt
    if (tep_has_category_subcategories($counter)) {
      $categories_string .= tep_image(DIR_WS_IMAGES . 'pointer_blue.gif', '');
    }
    else {
      $categories_string .= tep_image(DIR_WS_IMAGES . 'pointer_blue_light.gif', '');
    }

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $categories_string .= '<b>';
    }

    if ($cat_name == $tree[$counter]['name']) {
      $categories_string .= '<span class="errorText2">';
    }

// display category name
    $categories_string .= $tree[$counter]['name'];

		if ($cat_name == $tree[$counter]['name']) {
			$categories_string .= '</span>';
    }

    if (isset($cPath_array) && in_array($counter, $cPath_array)) {
      $categories_string .= '</b>';
    }
// 	EoF Category Box Enhancement

    $categories_string .= '</a>';

    if (SHOW_COUNTS == 'true') {
      $products_in_category = tep_count_products_in_category($counter);
      if ($products_in_category > 0) {
        $categories_string .= ' (' . $products_in_category . ')';
      }
    }

    $categories_string .= '  ';

    if ($tree[$counter]['next_id'] != false) {
      tep_show_category($tree[$counter]['next_id']);
    }
  }
?>
<!-- categories //--><table width="100%" border="0"><tr>

          <td>
<?php

// BoF - Contribution Category Box Enhancement 1.1
 if (isset($cPath_array)) {
		for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
				$categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
				if (tep_db_num_rows($categories_query) > 0)
				$categories = tep_db_fetch_array($categories_query);
		}
	$cat_name = $categories['categories_name'];
	}
// EoF Category Box Enhancement
// display category name

  $info_box_contents = array();
  $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

  new infoBoxHeading($info_box_contents, true, false);

  $categories_string = '';
  $tree = array();

  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
  while ($categories = tep_db_fetch_array($categories_query))  {
    $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                                'parent' => $categories['parent_id'],
                                                'level' => 0,
                                                'path' => $categories['categories_id'],
                                                'next_id' => false);

    if (isset($parent_id)) {
      $tree[$parent_id]['next_id'] = $categories['categories_id'];
    }

    $parent_id = $categories['categories_id'];

    if (!isset($first_element)) {
      $first_element = $categories['categories_id'];
    }
  }

  //------------------------
  if (tep_not_null($cPath)) {
    $new_path = '';
    reset($cPath_array);
    while (list($key, $value) = each($cPath_array)) {
      unset($parent_id);
      unset($first_id);
      $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");
      if (tep_db_num_rows($categories_query)) {
        $new_path .= $value;
        while ($row = tep_db_fetch_array($categories_query)) {
          $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                               'parent' => $row['parent_id'],
                                               'level' => $key+1,
                                               'path' => $new_path . '_' . $row['categories_id'],
                                               'next_id' => false);

          if (isset($parent_id)) {
            $tree[$parent_id]['next_id'] = $row['categories_id'];
          }

          $parent_id = $row['categories_id'];

          if (!isset($first_id)) {
            $first_id = $row['categories_id'];
          }


          $last_id = $row['categories_id'];
        }
        $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
        $tree[$value]['next_id'] = $first_id;
        $new_path .= '_';
      } else {
        break;
      }
    }
  }
  tep_show_category($first_element);

  $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);

// if ( (basename($PHP_SELF) != FILENAME_SPECIALS)) {
//$info_box_contents[] = array('align' => 'right',
 //                              'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '">' . SPECIAL_PRODUCTS_LINK . '</a></b></font>');
// }else{
// $info_box_contents[] = array('align' => 'right',
//                               'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_SPECIALS, '', 'NONSSL') . '">' . BOX_INFORMATION_SPECIALS . '</a></b></font>');
 // }
 //if ( (basename($PHP_SELF) != FILENAME_PRODUCTS_NEW)) {
//$info_box_contents[] = array('align' => 'right',
 //                              'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL') . '">' . NEW_PRODUCTS_LINK . '</a></b></font>');
// }else{
// $info_box_contents[] = array('align' => 'right',
//                               'text'  => '<font size=-2><b><a href="' . tep_href_link(FILENAME_PRODUCTS_NEW, '', 'NONSSL') . '">' . ALL_PRODUCTS_LINK .'</a></b></font>');
 // }
  function tep_get_paths($categories_array = '', $parent_id = '0', $indent = '', $path='') {
    global $languages_id;

    if (!is_array($categories_array)) $categories_array = array();

    $categories_query = tep_db_query("select c.categories_id, cd.categories_name from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where parent_id = '" . (int)$parent_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
    while ($categories = tep_db_fetch_array($categories_query)) {
      if ($parent_id=='0'){
	$categories_array[] = array('id' => $categories['categories_id'],
                                      'text' => $indent . $categories['categories_name']);
      }
      else{
	$categories_array[] = array('id' => $path . $parent_id . '_' .$categories['categories_id'],
        	                          'text' => $indent . $categories['categories_name']);
      }

      if ($categories['categories_id'] != $parent_id) {
	$this_path=$path;
	if ($parent_id != '0')
	  $this_path = $path . $parent_id . '_';
        $categories_array = tep_get_paths($categories_array, $categories['categories_id'], $indent . ' ', $this_path);
      }
    }

    return $categories_array;
  }
 
?>


 
<?php

 // $info_box_contents[] = array('form' => '<form action="' . tep_href_link(FILENAME_DEFAULT) . '" method="get">' . tep_hide_session_id(),
 //                              'align' => 'right',
 //                              'text'  => '<font size=-2><b>' . BOX_DROPDOWN_MENUS . '<br>' . tep_draw_pull_down_menu('cPath', tep_get_paths(array(array('id' => '</b></font>', 'text' => PULL_DOWN_DEFAULT))), $cPath, 'onchange="this.form.submit();" style="width: 200"')
 //                            );
  new infoBox($info_box_contents);
?>

            </td>

      </tr></table>
<!-- categories_eof //-->

Inviato: 20/04/2008, 21:02
da Tr4k
se metti un br, tutto ti và a capo, pure le categorie successive, non solo le sottocategorie......come ti hanno già detto, devi integrare un menù del genere in quella pagina!!!