Fork me on GitHub

Category list (third level) in pages module  Bottom

  • Hello,

    I have put a category list from news module into pages module and it works. I have also done that is document not belongs to category, it is not shown.

    This works well if we have only this structeure :

    Category 1 ==> Sub Category 1

    Bur if we have this structure :

    Category 1 ==> Sub Category 1 ==> Sub Category

    It does not show a sub category of sub category so a document can't be seen (to be see must put direct link)

    Can someone llok at the code to see where is errors. Thanks

    This is code of function that shows category in pnuser.php

    Code

    $rootcat = CategoryUtil::getCategoryByID($catregistry[$property]);
                if (!empty($rootcat)) {
                    $rootcat['path'] .= '/';
                    // Get all categories in this category property
                    $catcount = _countcategories($rootcat, $property, $catregistry, $uid);
                    $rootcat['pages_articlecount'] = $catcount['category']['pages_articlecount'];
                    $rootcat['pages_totalarticlecount'] = $catcount['category']['pages_totalarticlecount'];
                    $rootcat['pages_yourarticlecount'] = $catcount['category']['pages_yourarticlecount'];
                    $rootcat['subcategories'] = $catcount['subcategories'];
                    // Store data per property for listing in the overview
                    $propertiesdata[] = array('name'     => $property,
                                              'category' => $rootcat);
                }
            }
           
               
    }


    And this is code of template page that shows categories

    Code

    <!--[* Second level category display *]-->
                    <!--[if !empty($category.subcategories)]-->
                    <ul >
                    <!--[foreach from=$category.subcategories item='subcat']-->
                        <!--[array_field_isset assign='categoryname' array=$subcat.category.display_name field=$language returnValue=1]-->
                        <!--[if $categoryname eq '']--><!--[assign var='categoryname' value=$subcat.category.name]--><!--[/if]-->
                        <!--[array_field_isset assign='categorydesc' array=$subcat.category.display_desc field=$language returnValue=1]-->
                        <!--[assign var='categoryid' value=$subcat.category.id]-->
                       
            etc..        
                    <!--[* Third level category display *]-->
                    <!--[if !empty($property.category.subcategories.subcategories.subcategories.category)]-->
                    <ul >
                    <!--[foreach from=property.category.subcategories.subcategories.subcategories.category item='subcat']-->
                        <!--[array_field_isset assign='categoryname' array=$subcat.category.display_name field=$language returnValue=1]-->
                        <!--[if $categoryname eq '']--><!--[assign var='categoryname' value=$subcat.category.name]--><!--[/if]-->
                        <!--[array_field_isset assign='categorydesc' array=$subcat.category.display_desc field=$language returnValue=1]-->
                        <!--[assign var='categoryid' value=$subcat.category.id]-->


    actually i have on my template page this :
    *Category 1
    * Sub Category 1

    And i want to have this :
    *Category 1
    * Sub Category 1
    *Sub Category1
    With pndebug i got this :

    Code

    <!--[$category]-->category name ==>Category
                                 subcategories.category.name ==> Subcategory of Category
                                 subcategories.subcategories.category.name ==>Sub category of Subcategory of Category


    thanks



    edited by: nunizgb, datetimebrief
  • Hi, the Template code of the category list in News is only 2 level, so that makes sense icon_smile
    The categorylist PHP code does fill all subcategories, but the template does (at the moment) not display them. It is not recursively coded in the template, but explicit.

    So the template would have to be adjusted mainly.

    For an easier look of the code : http://code.zikula.org/news/browser/trunk/modules/News/pntemplates/news_user_categorylist.htm



    edited by: espaan, datetimebrief

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • Thanks espaan for reponse,

    I know that actually category list in news is 2 level so i made in Pages that have a Three levels but i got a problem with name and id of category.

    The category name of my sub category is not good (the name show for all sub category is same the name of parent category.

    Ex .

    Category
    Sub Category 1
    Sub Category 2
    Sub Category 1 (instead of Sub Sub Category 1)
    Sub Category 2 (instead of Sub Sub Category 2)

    I could not found where is error in this code i try evvrything but it doesn't works

    This code is for second level

    Code

    <!--[if !empty($category.subcategories)]-->
                           <ul >
                    <!--[foreach from=$category.subcategories item='subcat']-->

    This code is for third level :


    Code

    <!--[* Third level category display *]-->
                   <!--[if !empty($category.subcategories)]-->
                           <ul >
                    <!--[foreach from=$category.subcategories item='subcat1']-->
                        <!--[array_field_isset assign='categoryname' array=$subcat1.category.display_name field=$language returnValue=1]-->




    edited by: nunizgb, datetimebrief
  • Ah ok, you got the 3rd level already icon_biggrin because of hte long code listing I didn't check out the details icon_wink

    For the third level you need to chance $category into $subcat, since that is now the new "category" inside the foreach loop of $category.subcategories.

    I can imagine that there might be a more elegant "recursive" way of getting multiple levels, but it's not in (yet).

    So

    Code

    <!--[* Third level category display *]-->
                   <!--[if !empty($subcat.subcategories)]-->
                           <ul >
                    <!--[foreach from=$subcat.subcategories item='subcat1']-->
                        <!--[array_field_isset assign='categoryname' array=$subcat1.category.display_name field=$language returnValue=1]-->
    etc


    Does that work ?



    edited by: espaan, datetimebrief

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • Thanks Espaan,

    The code works i got correct name of category and its id but i got now this problem:

    I have this in categories :

    Category 1
    Sub Category 1
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3
    Sub Category 2
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3
    Sub Category 3 - 0 articles in that cat and 3 total in sub cat
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3 -there are 3 articles

    So in module pages i got a list of this :

    Category 1
    Sub Category 1
    Sub Category 2
    Sub Category 3 0 articles in that cat and 3 total
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3 there are 3 articles

    Tha category name and Id for sub-sub category are correct for last Sub Category but there aren't showing for others sub category.

    I will look at code to see foreach loop why doesnt shows category
    Thanks for help BTW

    I know that be easy to have only 2 level of category but i have a site that one artcle is for that sub-sub Category and one that could be in sub category beacause it concerne all sub-sub category.



    edited by: nunizgb, datetimebrief
  • Ok I found where was problem that not showin all categorries it is

    Code

    <!--[/foreach]-->
                   
                    <!--[/if]-->
                   
                    <!--[* end of second level subcategories *]-->


    Because at the end of first category there is not tag to close foreach so i have put at end of third level :

    Code

    </li>
                    <!--[/foreach]-->
                            </ul>
                    <!--[/if]-->
                   
                    <!--[/foreach]--> this was at end of second level
                   
                    <!--[/if]--> this was at end of second level
                    <!--[* end of third level subcategories *]-->


    So now i have a list of my categories and its sub categories ans its sub category correct

    Category 1 Currently no articles. (3 Total in subcategories | 3 contributed by you.)
    Sub Category 1
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3
    Sub Category 2
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3
    Sub Category 3 - Currently no articles. (3 Total in subcategories | 3 contributed by you.)
    Sub-sub Category 1
    Sub-sub Category 2
    Sub-sub Category 3 -3 articles. | 3 contributed by you.

    Thanks a lot Espaan for your help, if you want i can put a code of template to have this in code.zikula.org/news for category.

    Of course perhaps the code need to be clean and etc...

    And in future put in admin of news, pages if admin whant 3 level or more so the list is showing as many levels taht admin put in news, pages admin without he must change template of category list

    I have also in template of view function in pages done if cateory does not have article it is show no article under that category even if sub category of that category have articles.
  • Hi, great that you got it working icon_smile

    Can you put in a ticket in cozi/news and attach your code to it (or paste in the ticket in code markup). As an enhancement to have the number of category levels configurable in the categorylist. I can make multiple templates and based on a setting choose the right one. If you only have 1 cat level it makes sense ot have a simple 1 level template etc etc.

    Thanks.

    and BTW you can also file a ticket in the Parked project (cozi/parked) for the Pages module with the code. As a future enhancement. The Pages modules is still a nice simple static pages module and this kind of thing makes it more usable.



    edited by: espaan, datetimebrief

    --
    campertoday.nl, Module development, Dutch Zikula Community
  • Ok i will put code in Cozi news and pages and your idea to have multiple templates is perfect because some need 1 level some 2 levels and some 3 levels or more

This list is based on users active over the last 60 minutes.