Jump to content

Category / subcategory listing with thumbnail and file_exists ...


abcoclico

Recommended Posts

 Hello,

i just share this ugly part of code after waiting time to find how to display category thumbnail and using file_exist associated to this image ...

Hope this help ...

 

<h1 class="h1">{$category.name}</h1>
        {if $category.description}
            <div id="category-description" class="text-muted">{$category.description nofilter}</div>
            
        {/if}
    </div>
     <!-- <div class="text-xs-center hidden-md-up">
        <h1 class="h1">{$category.name}</h1>
    </div>-->
    

    
    
    {if isset($subcategories)}
        <!-- Subcategories -->
        <div id="subcategories">
           <!-- <p class="subcategory-heading">{l s='Subcategories'}</p>-->
            <ul class="clearfix">
                {foreach from=$subcategories item=subcategory}
                    <li>
                        <div class="subcategory-image">
                            <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img">
                                {if $subcategory.id_image}
{assign var="image" value=$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'category_default')}

{assign var="imagetest" value="img/c/`$subcategory.id_category`.jpg"}

{if $imagetest|file_exists}

<img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'small_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}"/>

{else}
<h5>{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</h5>
{/if}
                                
                                
                                {else}
                                   <h5>{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</h5>
                                {/if}
                            </a>
                        </div>
                       {if $imagetest|file_exists}  <h5><a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</a></h5>{/if}
                        {if $subcategory.description}
                            <div class="cat_desc">{$subcategory.description}</div>
                        {/if}
                    </li>
                {/foreach}
            </ul>
        </div>
    {/if}

 

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