Jump to content

Show all categories in a CMS Page?


Recommended Posts

I believe the only way to do it is by editing the cms controller, and if the cms page id matches the one you need, you can use Category::getCategories($id_lang) to get all of them. Assign to the tpl, and display inside cms.tpl is that smarty variable has been assigned

Link to comment
Share on other sites

Hi nemo1,

 

Thanks for the quick reply :) . I am new to prestashop. Could you please clarify more?

The Changes which U have suggested my affect the core files of prestashop right?

If yes then is there any other way to implement it without modifying core scripts.

 

Thanks

Link to comment
Share on other sites

getCategories() function is static function so in .tpl file you can use foreach loop on Category::getCategories()

 

 

something like:

{foreach from=Category::getCategories() item=category}
{$category.name}<br/>
{/foreach}
Link to comment
Share on other sites

Sure! 

 

check out this tut on overrides:

http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingacontroller

 

You have to override the CMSController.php file, in override/controllers/front

 

In the initContent method, check if Tools::getValue('id_cms') equals the id of the cms page you want the list to appear. If it does use

 

Category::getCategories($id_lang) 

 

To get categories, then $this->context->smarty->assign('thevariablenameinsmarty',$categories_variable_name);

 

Finally, inside cms.tpl (template folder) if $thevariablenameinsmarty is assigned, display categories

Link to comment
Share on other sites

I have studies and created a sample code in my_module\override\controllers\front\CmsController.php

 

In which I have written following code

 

<?php

class MycmsController extends CmsControllerCore{
    public function init()
    {
        $id_cms = (int)Tools::getValue('id_cms');
                echo $id_cms;
                die;
    }

 

  public function initContent()
    {
        $id_cms = (int)Tools::getValue('id_cms');
                echo $id_cms;
                die;
    }
    
}

 

I have also deleted the class_index.php  file from cache folder but still not getting cms page id and it not event die(stops) the execution.

 

Help me please

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

Thanks for the reply but it still not working for me :(

 

<?php
class cmsController extends CmsControllerCore{
    public function init()
    {
        $id_cms = (int)Tools::getValue('id_cms');
                echo $id_cms;
                die;
    }

 

  public function initContent()
    {
        $id_cms = (int)Tools::getValue('id_cms');
                echo $id_cms;
                die;
    }
    
}

Link to comment
Share on other sites

  • 2 weeks later...

Hi

 

I have used  $categories = Category::getCategories(); to get all categories it is working fine for me but I didn't get category image on the tpl file can you please let me know how can I get that image. I am also not getting $category.id_image parameter to get image

 

I got this array for each category :

 

[infos] => Array
(
[id_category] => 13
[id_parent] => 2
[id_shop_default] => 1
[level_depth] => 2
[nleft] => 3
[nright] => 4
[active] => 1
[date_add] => 2014-05-23 01:58:27
[date_upd] => 2014-05-28 02:30:24
[position] => 1
[is_root_category] => 0
[id_shop] => 1
[id_lang] => 1
[name] => Appearance Protection Packages
[description] =>
[link_rewrite] => appearance-protection-packages
[meta_title] =>
[meta_keywords] =>
[meta_description] =>
)

 

How can I get image for this category please help.

Link to comment
Share on other sites

  • 2 years later...

 

getCategories() function is static function so in .tpl file you can use foreach loop on Category::getCategories()

 

 

something like:

{foreach from=Category::getCategories() item=category}
{$category.name}<br/>
{/foreach}

 

in this way the only thing to override is the .tpl and not the cmsController.php?

 
Link to comment
Share on other sites

  • 7 months later...
  • 2 years later...
On 7/14/2017 at 11:23 AM, mhdcasa said:

hello ALL

i want disppaly all parent category in cms pge and i did all step before but i cant see an result 

can you help me ?

Hello did you solve that? I know it's been a long time ago but, I'm trying to do the same now in prestashop 1.7.5.1.

@Chetanilead would it be possible to get the module you developed?

Thanks.

Link to comment
Share on other sites

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...