Jump to content

(Solved) Show only the subcategories of a specific parent Category


abdamu

Recommended Posts

Hello I am interested in only showing the subcategories that I need from only the parent categories that I need. That is, From the parent categories: Woman another Man and another Child (for example) I would only like to show the subcategories of Woman and Children, and of Man that are not shown.
You can do something from the category.tpl file with Foreach and an If right? Adding the IDs but I don't know how, I can't find any complete code in the forum.
I hope your help if possible.

Data:
Prestashop 1.7.7.6
Classic template
Php 7.3


Greetings

Edited by abdamu (see edit history)
Link to comment
Share on other sites

hace 20 minutos, endriu107 dijo:

Probably this will help you:

https://mypresta.eu/prestashop-17/display-available-subcategories.html

This code is a little out of date but it should give you realy big hint.

{foreach from=$subcategories item=subcategory}

Thanks for your quick response ..... but with that I can't get to everything. With the foreach it makes the call, but of course I have the doubt that it only shows the ids for example of the subcategories that I want to show.

Edited by abdamu (see edit history)
Link to comment
Share on other sites

{if $category->id AND $category->active}
                        {if ($category->id_category == 150) OR ($category->id_parent == 150) OR ($category->id_parent == 330) OR ($category->id_parent == 167) OR ($category->id_parent == 155)}
 

I have found this code on the forum, but it doesn't work for me or I'm not applying it well. I also attach the complete code of the category.tpl in case some charitable soul can help me 😢

 

{**
 * Copyright since 2007 PrestaShop SA and Contributors
 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License 3.0 (AFL-3.0)
 * that is bundled with this package in the file LICENSE.md.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/AFL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://devdocs.prestashop.com/ for more information.
 *
 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
 * @copyright Since 2007 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
 *}
<div id="js-product-list-header">
    {if $listing.pagination.items_shown_from == 1}
        <div class="block-category card card-block">
            <h1 class="h1">{$category.name}</h1>
            <div class="block-category-inner">
                {if $category.description}
                    <div id="category-description" class="text-muted">{$category.description nofilter}</div>
                {/if}
                {if $category.image.large.url}
                    <div class="category-cover">
                        <img src="{$category.image.large.url}" alt="{if !empty($category.image.legend)}{$category.image.legend}{else}{$category.name}{/if}">
                    </div>
                {/if}
            </div>
        </div>
    {/if}
</div>

 

Link to comment
Share on other sites

En 18/8/2021 a las 1:10 PM, endriu107 dijo:

If you put {dump} in tpl file in popup you will see all variables you have access, and by dumping specific variable you have access to it data.

array(6) { ["title"]=> string(0) "" 
["canonical"]=> string(50) "https://test.es/new/es/62-test-test2" 
["meta"]=> array(4) { ["title"]=> string(47) "xx" 
["description"]=> string(160) "xxx" 
["keywords"]=> string(105) "xx" ["robots"]=> string(5) "index" }
["page_name"]=> string(8) "category" ["body_classes"]=> array(11) { ["lang-es"]=> bool(true) ["lang-rtl"]=> bool(false) 
["country-ES"]=> bool(true) ["currency-EUR"]=> bool(true)
["layout-left-column"]=> bool(true) ["page-category"]=> bool(true) ["tax-display-enabled"]=> bool(true) 
["category-id-62"]=> bool(true) ["xxs"]=> bool(true) 
["category-id-parent-2"]=> bool(true)
["category-depth-level-2"]=> bool(true) } 
["admin_notifications"]=> array(0) { } }

You mean this? I have applied the  {$page|@var_dump} in category.tpl and that is the result....

Link to comment
Share on other sites

hace 16 minutos, endriu107 dijo:

I make mistake in previous answer it should be {debug} not dump.

You can check category id by:

{if $category.id == 3} TEXT IN CATEGORY ID 3 {/if}

 

Yes, I add this code it shows the "Text in category ID 3" works fine. But that's not what I'm looking for. What I am looking for I have said at the beginning of the post.
Thanks friend for your quick response

Link to comment
Share on other sites

$category 	Array (2)
value => Array (17)
  nleft => "98"
  nright => "99"
  level_depth => "3"
  id_parent => "62"
  id_shop_default => "1"
  is_root_category => "0"
  position => "0"
  date_add => "2021-05-26 17:49:59"
  date_upd => "2021-05-18 19:13:57"
  name => "test"
  link_rewrite => "test"
  description => "<p><strong>test"
  meta_title => "test"
  meta_description => "test"
  meta_keywords => ""
  id => 87
  image => null
scope => "Smarty object"

With {debug} I get the pop up where it tells me, being for example in this case, in a subcategory....

Link to comment
Share on other sites

hace 2 horas, endriu107 dijo:

I'm not shure what else you need, i give you code to display anything you want in specific category, also I give you link to page where is code to display subcategories, put it all together.

Friend, I think you did not understand what I want to do ... You may not have explained me well.

I just want to show category ID 62 the 2 subcategories I have. But in the other main categories, your subcategories should always be hidden.

I will seek help elsewhere or someone who can understand what I am looking for ...

PS: I am not a programmer or developer ;)

Link to comment
Share on other sites

Like I said before you got all you need just put it together, here sample code of one subacategory in one category:

{if $category.id == 62}
  {if isset($subcategories)}
    {foreach from=$subcategories item=subcategory}
      {if $subcategory.id_category == 105}
        Here Display subcategory with ID 105 in category with ID 62
      {/if}
    {/foreach}
  {/if}
{/if}

 

Link to comment
Share on other sites

  • 2 weeks later...

ok thnaks

En 22/8/2021 a las 9:23 AM, endriu107 dijo:

Like I said before you got all you need just put it together, here sample code of one subacategory in one category:

{if $category.id == 62}
  {if isset($subcategories)}
    {foreach from=$subcategories item=subcategory}
      {if $subcategory.id_category == 105}
        Here Display subcategory with ID 105 in category with ID 62
      {/if}
    {/foreach}
  {/if}
{/if}

 

ok thanks solved

Link to comment
Share on other sites

  • abdamu changed the title to (Solved) Show only the subcategories of a specific parent Category

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...