megamiska Merchant Fra Slovenia Medlem siden okt. 2023 megamiska jan. 29 2025 08:48 a.m. Hi, I want to show just specific categories / subcategories in box_categories.inc on homepage. What I need to modify in code bellow? <?php foreach ($categories as $category) echo functions::draw_listing_category($category); ?> Thanks in advance!
dodo Moderator Fra Lithuania Medlem siden mar. 2016 dodo jan. 29 2025 09:41 a.m. Not sure what you are trying to achieve here but you can try: <?php $categories = array(1, 3, 5); foreach ($categories as $category) echo functions::draw_listing_category($category); ?> Use categories ids instead 1,3,5
megamiska Merchant Fra Slovenia Medlem siden okt. 2023 megamiska jan. 29 2025 10:45 a.m. Thanks! I want to show just specific categories on homepage instead all master categories. Seems this is not working... Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 67) Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 68) Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 69) Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 71) Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 72) Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 73) Warning: Trying to access array offset on value of type int in ~/includes/functions/func_draw.inc.php (Line 80)
tim Founder Fra Sweden Medlem siden mai 2013 tim jan. 29 2025 03:46 p.m. Swap out functions::catalog_categories_query() with your own custom database::query(). <?php $box_categories_cache_token = cache::token('box_categories', ['language'], 'file'); if (cache::capture($box_categories_cache_token)) { $categories_query = database::query( "select c.id, c.parent_id, c.image, ci.name, ci.short_description, c.priority, c.date_updated from ". DB_TABLE_PREFIX ."categories c left join ". DB_TABLE_PREFIX ."categories_info ci on (ci.category_id = c.id and ci.language_code = '". database::input(language::$selected['code']) ."') where c.status and c.id in (1, 3, 5) order by c.priority asc, ci.name asc;" ); if (database::num_rows($categories_query)) { $box_categories = new ent_view(); $box_categories->snippets = [ 'categories' => [], ]; while ($category = database::fetch($categories_query)) { $box_categories->snippets['categories'][] = $category; } echo $box_categories->stitch('views/box_categories'); } cache::end_capture($box_categories_cache_token); }
megamiska Merchant Fra Slovenia Medlem siden okt. 2023 megamiska jan. 29 2025 05:06 p.m. Thanks Tim! Do I need to put this into index.inc.php?
jackmaessen LiteCart Fan Fra Netherlands Medlem siden des. 2022 jackmaessen jan. 29 2025 05:30 p.m. No. In file includes/boxes/box_categories.inc.php: replace this line $categories_query = functions::catalog_categories_query(); with this code: $categories_query = database::query( "select c.id, c.parent_id, c.image, ci.name, ci.short_description, c.priority, c.date_updated from ". DB_TABLE_PREFIX ."categories c left join ". DB_TABLE_PREFIX ."categories_info ci on (ci.category_id = c.id and ci.language_code = '". database::input(language::$selected['code']) ."') where c.status and c.id in (1, 3, 5) order by c.priority asc, ci.name asc;" ); The line and c.id in (1, 3, 5) means: show only categories with the id 1, 3 and 5
megamiska Merchant Fra Slovenia Medlem siden okt. 2023 megamiska jan. 29 2025 05:41 p.m. Thanks jackmaessen! Like this: <section id="box-categories" class="box"> <div class="card-header"> <h1 class="card-title"><?php echo language::translate('title_shop_by_category', 'Shop By Category'); ?></h1> </div> <div class="card-body"> <div class="listing categories"> <?php $box_categories_cache_token = cache::token('box_categories', ['language'], 'file'); if (cache::capture($box_categories_cache_token)) { $categories_query = database::query( "select c.id, c.parent_id, c.image, ci.name, ci.short_description, c.priority, c.date_updated from ". DB_TABLE_PREFIX ."categories c left join ". DB_TABLE_PREFIX ."categories_info ci on (ci.category_id = c.id and ci.language_code = '". database::input(language::$selected['code']) ."') where c.status and c.id in (44, 443, 316) order by c.priority asc, ci.name asc;" ); if (database::num_rows($categories_query)) { $box_categories = new ent_view(); $box_categories->snippets = [ 'categories' => [44, 443, 316], ]; while ($category = database::fetch($categories_query)) { $box_categories->snippets['categories'][] = $category; } echo $box_categories->stitch('views/box_categories'); } cache::end_capture($box_categories_cache_token); } </div> </div> </section> I replace and get error...
jackmaessen LiteCart Fan Fra Netherlands Medlem siden des. 2022 jackmaessen jan. 29 2025 05:49 p.m. You have the wrong file. You must look for: includes/boxes/box_categories.inc.php (the logic file) https://github.com/litecart/litecart/blob/dev/public_html/includes/boxes/box_categories.inc.php
megamiska Merchant Fra Slovenia Medlem siden okt. 2023 megamiska jan. 29 2025 05:53 p.m. Oh I see now. Thanks, it works!