Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011
    Location
    Adelaide, Australia
    Posts
    1,113
    Plugin Contributions
    1

    Default Modify which Categories Show on Main Page

    v.1.5.5f PHP7.1

    I would like to modify which categories actually show up on the main page when admin/configuration/layout settings/Categories - Always show on Main Page is set to on .... there are some I do not want on the main page.

    In an 'associated' thread Design75 kindly suggested the file to modify was includes\modules\pages\index\main_template_vars.php .... the problem I have is that it looks far too confusing to me, too many sections that could be modified but likely shouldn't.

    So can someone please give me a helping hand to isolate which section should be modified and an example please of 'how' it should be modified to exclude certain categories.

    many thanks,
    Mike

    Code:
    <?php
    /**
     * index main_template_vars.php 
     *
     * @package page
     * @copyright Copyright 2003-2016 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: Author: DrByte  Thu Jan 7 22:43:33 2016 -0500 Modified in v1.5.5 $
     */
    
    // This should be first line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_START_INDEX_MAIN_TEMPLATE_VARS');
    
    //die($category_depth);
    //die($_GET['music_genre_id']);
    
    // release manufacturers_id when nothing is there so a blank filter is not setup.
    // this will result in the home page, if used
    if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] <= 0) {
      unset($_GET['manufacturers_id']);
      unset($manufacturers_id);
    }
    
    // release music_genre_id when nothing is there so a blank filter is not setup.
    // this will result in the home page, if used
    if (isset($_GET['music_genre_id']) && $_GET['music_genre_id'] <= 0) {
      unset($_GET['music_genre_id']);
      unset($music_genre_id);
    }
    
    // release record_company_id when nothing is there so a blank filter is not setup.
    // this will result in the home page, if used
    if (isset($_GET['record_company_id']) && $_GET['record_company_id'] <= 0) {
      unset($_GET['record_company_id']);
      unset($record_company_id);
    }
    
    // only release typefilter if both record_company_id and music_genre_id are blank
    // this will result in the home page, if used
    if ((isset($_GET['record_company_id']) && $_GET['record_company_id'] <= 0) and (isset($_GET['music_genre_id']) && $_GET['music_genre_id'] <= 0) ) {
      unset($_GET['typefilter']);
      unset($typefilter);
    }
    
    // release filter for category or manufacturer when nothing is there
    if (isset($_GET['filter_id']) && $_GET['filter_id'] <= 0) {
      unset($_GET['filter_id']);
      unset($filter_id);
    }
    
    // release alpha filter when nothing is there
    if (isset($_GET['alpha_filter_id']) && $_GET['alpha_filter_id'] <= 0) {
      unset($_GET['alpha_filter_id']);
      unset($alpha_filter_id);
    }
    
    // hook to notifier so that additional product-type-specific vars can be released too
    $zco_notifier->notify('NOTIFY_HEADER_INDEX_MAIN_TEMPLATE_VARS_RELEASE_PRODUCT_TYPE_VARS');
    
    
    if ($category_depth == 'nested')
    {
      $sql = "SELECT cd.categories_name, c.categories_image
              FROM   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
              WHERE      c.categories_id = :categoriesID
              AND        cd.categories_id = :categoriesID
              AND        cd.language_id = :languagesID
              AND        c.categories_status= '1'";
    
      $sql = $db->bindVars($sql, ':categoriesID', $current_category_id, 'integer');
      $sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
      $category = $db->Execute($sql);
    
      if (isset($cPath) && strpos($cPath, '_'))
      {
        // check to see if there are deeper categories within the current category
        $category_links = array_reverse($cPath_array);
        for($i=0, $n=sizeof($category_links); $i<$n; $i++)
        {
          $sql = "SELECT count(*) AS total
                  FROM   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                  WHERE      c.parent_id = :parentID
                  AND        c.categories_id = cd.categories_id
                  AND        cd.language_id = :languagesID
                  AND        c.categories_status= '1'";
    
          $sql = $db->bindVars($sql, ':parentID', $category_links[$i], 'integer');
          $sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
          $categories = $db->Execute($sql);
    
          if ($categories->fields['total'] < 1)
          {
            // do nothing, go through the loop
          } else {
            $categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
                                 FROM   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                                 WHERE      c.parent_id = :parentID
                                 AND        c.categories_id = cd.categories_id
                                 AND        cd.language_id = :languagesID
                                 AND        c.categories_status= '1'
                                 ORDER BY   sort_order, cd.categories_name";
    
            $categories_query = $db->bindVars($categories_query, ':parentID', $category_links[$i], 'integer');
            $categories_query = $db->bindVars($categories_query, ':languagesID', $_SESSION['languages_id'], 'integer');
            break; // we've found the deepest category the customer is in
          }
        }
      } else {
        $categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
                             FROM   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                             WHERE      c.parent_id = :parentID
                             AND        c.categories_id = cd.categories_id
                             AND        cd.language_id = :languagesID
                             AND        c.categories_status= '1'
                             ORDER BY   sort_order, cd.categories_name";
    
        $categories_query = $db->bindVars($categories_query, ':parentID', $current_category_id, 'integer');
        $categories_query = $db->bindVars($categories_query, ':languagesID', $_SESSION['languages_id'], 'integer');
      }
      $categories = $db->Execute($categories_query);
      $number_of_categories = $categories->RecordCount();
      $new_products_category_id = $current_category_id;
    
      /////////////////////////////////////////////////////////////////////////////////////////////////////
      $tpl_page_body = 'tpl_index_categories.php';
      /////////////////////////////////////////////////////////////////////////////////////////////////////
    
      //  } elseif ($category_depth == 'products' || isset($_GET['manufacturers_id']) || isset($_GET['music_genre_id'])) {
    } elseif ($category_depth == 'products' || zen_check_url_get_terms()) {
      if (SHOW_PRODUCT_INFO_ALL_PRODUCTS == '1') {
        // set a category filter
        $new_products_category_id = $cPath;
      } else {
        // do not set the category
      }
      // create column list
      $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
      'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
      'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
      'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
      'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
      'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
      'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE);
    
      /*                         ,
      'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW);
      */
      asort($define_list);
      reset($define_list);
      $column_list = array();
      foreach ($define_list as $key => $value)
      {
        if ($value > 0) $column_list[] = $key;
      }
    
      $select_column_list = '';
    
      for ($i=0, $n=sizeof($column_list); $i<$n; $i++)
      {
        switch ($column_list[$i])
        {
          case 'PRODUCT_LIST_MODEL':
          $select_column_list .= 'p.products_model, ';
          break;
          case 'PRODUCT_LIST_NAME':
          $select_column_list .= 'pd.products_name, ';
          break;
          case 'PRODUCT_LIST_MANUFACTURER':
          $select_column_list .= 'm.manufacturers_name, ';
          break;
          case 'PRODUCT_LIST_QUANTITY':
          $select_column_list .= 'p.products_quantity, ';
          break;
          case 'PRODUCT_LIST_IMAGE':
          $select_column_list .= 'p.products_image, ';
          break;
          case 'PRODUCT_LIST_WEIGHT':
          $select_column_list .= 'p.products_weight, ';
          break;
        }
      }
      // always add quantity regardless of whether or not it is in the listing for add to cart buttons
      if (PRODUCT_LIST_QUANTITY < 1) {
        $select_column_list .= 'p.products_quantity, ';
      }
    
      // set the product filters according to selected product type
      $typefilter = 'default';
      if (isset($_GET['typefilter'])) $typefilter = $_GET['typefilter'];
      require(zen_get_index_filters_directory($typefilter . '_filter.php'));
    
    
    
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////
      $tpl_page_body = 'tpl_index_product_list.php';
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    } else {
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////
      $tpl_page_body = 'tpl_index_default.php';
      ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }
    $current_categories_description = "";
    $current_categories_name = "";
    // categories_description
    $sql = "SELECT categories_description, categories_name
            FROM " . TABLE_CATEGORIES_DESCRIPTION . "
            WHERE categories_id= :categoriesID
            AND language_id = :languagesID";
    
    $sql = $db->bindVars($sql, ':categoriesID', $current_category_id, 'integer');
    $sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
    $categories_description_lookup = $db->Execute($sql);
    if ($categories_description_lookup->RecordCount() > 0) {
      $current_categories_description = $categories_description_lookup->fields['categories_description'];
      $current_categories_name = $categories_description_lookup->fields['categories_name'];
    }
    
    if ($current_categories_name == '' && isset($_GET['manufacturers_id'])) {
      $result = $db->Execute( "SELECT * FROM " . TABLE_MANUFACTURERS . "
                               WHERE manufacturers_id = " . (int)$_GET['manufacturers_id'] . " LIMIT 1");
      if (!$result->EOF) $current_categories_name = $result->fields['manufacturers_name'];
    }
    if ($current_categories_name == '' && isset($_GET['record_company_id'])) {
      $result = $db->Execute( "SELECT * FROM " . TABLE_RECORD_COMPANY . "
                               WHERE record_company_id = " . (int)$_GET['record_company_id'] . " LIMIT 1");
      if (!$result->EOF) $current_categories_name = $result->fields['record_company_name'];
    }
    if ($current_categories_name == '' && isset($_GET['music_genre_id'])) {
      $result = $db->Execute( "SELECT * FROM " . TABLE_MUSIC_GENRE . "
                               WHERE music_genre_id = " . (int)$_GET['music_genre_id'] . " LIMIT 1");
      if (!$result->EOF) $current_categories_name = $result->fields['music_genre_name'];
    }
    $zco_notifier->notify('NOTIFY_HEADER_INDEX_MAIN_TEMPLATE_VARS_PAGE_BODY', NULL, $tpl_page_body, $current_categories_name);
    
    require($template->get_template_dir($tpl_page_body, DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . $tpl_page_body);
    
    // This should be last line of the script:
    $zco_notifier->notify('NOTIFY_HEADER_END_INDEX_MAIN_TEMPLATE_VARS', NULL, $current_categories_description);

  2. #2
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,379
    Plugin Contributions
    15

    Default Re: Modify which Categories Show on Main Page

    You'll need to add category id exclusions to the $categories database query in - includes/modules/pages/index/main_template_vars.php



    PHP Code:
    if ($category_depth == 'nested')
    {
      
    $sql "SELECT cd.categories_name, c.categories_image
              FROM   " 
    TABLE_CATEGORIES " c, " TABLE_CATEGORIES_DESCRIPTION " cd
              WHERE      c.categories_id = :categoriesID
              AND        cd.categories_id = :categoriesID
              AND        cd.language_id = :languagesID
              AND        c.categories_status= '1'"
    ;

      
    $sql $db->bindVars($sql':categoriesID'$current_category_id'integer');
      
    $sql $db->bindVars($sql':languagesID'$_SESSION['languages_id'], 'integer');
      
    $category $db->Execute($sql);

      if (isset(
    $cPath) && strpos($cPath'_'))
      {
        
    // check to see if there are deeper categories within the current category
        
    $category_links array_reverse($cPath_array);
        for(
    $i=0$n=sizeof($category_links); $i<$n$i++)
        {
          
    $sql "SELECT count(*) AS total
                  FROM   " 
    TABLE_CATEGORIES " c, " TABLE_CATEGORIES_DESCRIPTION " cd
                  WHERE      c.parent_id = :parentID
                  AND        c.categories_id = cd.categories_id
                  AND        cd.language_id = :languagesID
                  AND        c.categories_status= '1'"
    ;

          
    $sql $db->bindVars($sql':parentID'$category_links[$i], 'integer');
          
    $sql $db->bindVars($sql':languagesID'$_SESSION['languages_id'], 'integer');
          
    $categories $db->Execute($sql);

          if (
    $categories->fields['total'] < 1)
          {
            
    // do nothing, go through the loop
          
    } else {
            
    $categories_query "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
                                 FROM   " 
    TABLE_CATEGORIES " c, " TABLE_CATEGORIES_DESCRIPTION " cd
                                 WHERE      c.parent_id = :parentID
                                 AND        c.categories_id = cd.categories_id
                                 AND        cd.language_id = :languagesID
                                 AND        c.categories_status= '1'
                                 ORDER BY   sort_order, cd.categories_name"
    ;

            
    $categories_query $db->bindVars($categories_query':parentID'$category_links[$i], 'integer');
            
    $categories_query $db->bindVars($categories_query':languagesID'$_SESSION['languages_id'], 'integer');
            break; 
    // we've found the deepest category the customer is in
          
    }
        }
      } else {
        
    $categories_query "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id
                             FROM   " 
    TABLE_CATEGORIES " c, " TABLE_CATEGORIES_DESCRIPTION " cd
                             WHERE      c.parent_id = :parentID
                             AND        c.categories_id = cd.categories_id
                             AND        cd.language_id = :languagesID
                             AND        c.categories_status= '1'
                             ORDER BY   sort_order, cd.categories_name"
    ;

        
    $categories_query $db->bindVars($categories_query':parentID'$current_category_id'integer');
        
    $categories_query $db->bindVars($categories_query':languagesID'$_SESSION['languages_id'], 'integer');
      }
      
    $categories $db->Execute($categories_query);
      
    $number_of_categories $categories->RecordCount();
      
    $new_products_category_id $current_category_id;

      
    /////////////////////////////////////////////////////////////////////////////////////////////////////
      
    $tpl_page_body 'tpl_index_categories.php';
      
    ///////////////////////////////////////////////////////////////////////////////////////////////////// 
    Twitch.
    http://www.twitchtoo.com - Do you work for free? Please donate.
    Twitch Wholesale + Attributes for 1.55f, TAP Thumb for 155f and more...

 

 

Similar Threads

  1. v151 show sub categories in categories menu on main page
    By shags38 in forum General Questions
    Replies: 2
    Last Post: 17 May 2017, 06:12 AM
  2. categories wont show on main page
    By samanthar in forum General Questions
    Replies: 5
    Last Post: 8 Feb 2010, 10:41 PM
  3. Show categories on the main page
    By creff in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 28 Oct 2009, 02:36 AM
  4. Show sub categories for one main category on main page
    By relspeedwagon in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 12 Oct 2008, 11:29 PM
  5. Always Show Categories on Main Page...
    By Alex Clarke in forum General Questions
    Replies: 4
    Last Post: 25 Feb 2007, 12:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR