Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Very Popular

    Remove (and 5 more) from categories widget block

    Jimi Wikman

    The categories widget block will collapse the number of subcategories if there are more than 5 subcategories. This can be fixed by changing the code quite easily.

    You first need to locate your category widget template, which is located in your theme files. Go to your theme and click on the "Edit HTML and CSS". Then find the file under cms -> front -> widgets -> categories.

    image.png

     

    This is the code for the category widget block:

    {{$catClass = '\IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId;}}
    {{$categories = $catClass::roots();}}
    {{if !empty( $categories )}}
    	<h3 class='ipsWidget_title ipsType_reset'>{lang="categories"}</h3>
    	<div class='ipsSideMenu ipsAreaBackground_reset ipsPad_half'>
    		<ul class='ipsSideMenu_list'>
    			{{foreach $categories as $category}}
    				<li>
    					<a href="{$category->url()}" class='ipsSideMenu_item ipsTruncate ipsTruncate_line'><span class='ipsBadge ipsBadge_style1 ipsPos_right'>{expression="\IPS\cms\Records::contentCount( $category )"}</span><strong class='ipsType_normal'>{$category->_title}</strong></a>
    					{{if $category->hasChildren()}}
    						<ul class="ipsSideMenu_list">
    							{{foreach $category->children() as $idx => $subcategory}}
    								<li>
    									{{if $idx >= 5}}
    										<a href='{$category->url()}' class='ipsSideMenu_item'><span class='ipsType_light ipsType_small'>{lang="and_x_more" sprintf="count( $category->children() ) - 5"}</span></a>
    										{{break;}}
    									{{else}}
    										<a href="{$subcategory->url()}" class='ipsSideMenu_item ipsTruncate ipsTruncate_line'><strong class='ipsPos_right ipsType_small'>{expression="\IPS\cms\Records::contentCount( $subcategory )"}</strong>{$subcategory->_title}</a>
    									{{endif}}
    								</li>
    							{{endforeach}}
    						</ul>
    					{{endif}}
    				</li>
    			{{endforeach}}
    		</ul>
    		<p class='ipsType_center'>
    			<a href='{$url->setQueryString('show','categories')}' class=''>{lang="cms_show_categories"} &nbsp;<i class='fa fa-caret-right'></i></a>
    		</p>
    	</div>
    {{endif}}

    In this code you will see this snippet:

    {if $idx >= 5}}
    <a href='{$category->url()}' class='ipsSideMenu_item'><span class='ipsType_light ipsType_small'>{lang="and_x_more" sprintf="count( $category->children() ) - 5"}</span></a>
    {{break;}}
    {{else}}
    <a href="{$subcategory->url()}" class='ipsSideMenu_item ipsTruncate ipsTruncate_line'><strong class='ipsPos_right ipsType_small'>{expression="\IPS\cms\Records::contentCount( $subcategory )"}</strong>{$subcategory->_title}</a>
    {{endif}}

    This is what control the behavior so all we need to do is to remove the top part of this and the ending endif. This will look like this:

    {{$catClass = '\IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId;}}
    {{$categories = $catClass::roots();}}
    {{if !empty( $categories )}}
    	<h3 class='ipsWidget_title ipsType_reset'>{lang="categories"}</h3>
    	<div class='ipsSideMenu ipsAreaBackground_reset ipsPad_half'>
    		<ul class='ipsSideMenu_list'>
    			{{foreach $categories as $category}}
    				<li>
    					<a href="{$category->url()}" class='ipsSideMenu_item ipsTruncate ipsTruncate_line'><span class='ipsBadge ipsBadge_style1 ipsPos_right'>{expression="\IPS\cms\Records::contentCount( $category )"}</span><strong class='ipsType_normal'>{$category->_title}</strong></a>
    					{{if $category->hasChildren()}}
    						<ul class="ipsSideMenu_list">
    							{{foreach $category->children() as $idx => $subcategory}}
    								<li>
    									
    										<a href="{$subcategory->url()}" class='ipsSideMenu_item ipsTruncate ipsTruncate_line'><strong class='ipsPos_right ipsType_small'>{expression="\IPS\cms\Records::contentCount( $subcategory )"}</strong>{$subcategory->_title}</a>
    									
    								</li>
    							{{endforeach}}
    						</ul>
    					{{endif}}
    				</li>
    			{{endforeach}}
    		</ul>
    		<p class='ipsType_center'>
    			<a href='{$url->setQueryString('show','categories')}' class=''>{lang="cms_show_categories"} &nbsp;<i class='fa fa-caret-right'></i></a>
    		</p>
    	</div>
    {{endif}}

     

    image.png

    image.png

    image.png

    image.png

    image.png

    image.png

    image.png

    image.png

    image.png

    Skärmbild 2022-09-19 143856.jpg

    Skärmbild 2022-09-19 143856.jpg

    image.png

    Skärmbild 2022-09-19 143856.jpg

    Skärmbild 2022-09-19 143856.jpg

    image.png

    Skärmbild 2022-09-19 143856.jpg

    Discuss the Guide

    Recommended Comments

    There are no comments to display.



    Please sign in to comment

    You will be able to leave a comment after signing in



    Sign In Now
     Share

    • Invision Community Playbook

  • Latest Updates

×
×
  • Create New...