0

I have many pages that use this tag but on one of them I am getting a white screen/server error. This page happens to be one that has the most entries that use the snippet. When I remove the snippet the page loads as expected.

My server has 700M of memory allocated.

    {categories}                
        {exp:switchee variable = "{category_id}" parse="inward"}                        
            {case value="2"}
            <a href="{site_url}dining/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-restaurant"></i>
            </div>
            </a>    
            {/case}             
            {case value="38"}
            <a href="{site_url}nightlife/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-bar"></i>
            </div>
            </a>
            {/case}             
            {case value="4"}
            <a href="{site_url}arts-culture/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-art"></i>
            </div>
            </a>
            {/case}                     
            {case value="36"}
            <a href="{site_url}nightlife/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-brewery"></i>
            </div>
            </a>
            {/case}             
            {case value="1"}
            <a href="{site_url}shopping/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-retail"></i>
            </div>
            </a>
            {/case}             
            {case value="7"}
            <a href="{site_url}shopping/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-service"></i>
            </div>
            </a>
            {/case}                     
            {case value="3"}
            <a href="{site_url}dining/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="Coffee-Bakery">
                <i class="icon-coffee"></i>
            </div>
            </a>
            {/case}         

            {case value="11"}
            <a href="{site_url}arts-culture/category/{category_url_title}">
            <div class="category-icons" rel="tooltip" title="{category_name}">
                <i class="icon-community"></i>
            </div>
            </a>
            {/case}         
        {/exp:switchee}
{/categories}

Any ideas? Is the code just THAT inefficient?

6
  • What's the error you're receiving or are you just getting a white screen? Also, why are you using switchee? I don't see the use for it, unless the case value doesn't match a category id. Also, just as a note, the RAM on your machine isn't the same as how much memory is allocated to PHP, MySQL, and Apache, so it could be one of those running out of memory, if they are set to their defaults, about 64MB each, generally. Jan 23 '13 at 7:43
  • Because I am not using all categories only selected ones. Sorry, I have 700M 'allocated'. memory_limit 700M Don't know about mySQLor Apache. I am on Nexcess EEP-200 Hosting. Jan 23 '13 at 7:51
  • You're repeating quite a bit of code, which isn't ideal, but in terms of processing that's all basic stuff and shouldn't generate much overhead. Do you have a large number of categories? If you enable debugging (either via EE prefs or $debug = 1 in index.php) you should get a PHP error instead of a white screen. Once you have that it shouldn't be too hard to figure out what's going on.
    – Dom Stubbs
    Jan 23 '13 at 12:10
  • There are a large number of categories. I don't know why I didn't use show="1|2|3|4|7|11|36|38" to limit the categories. I changed it to that and the page is now loading. Must have been mySQL memory? Jan 23 '13 at 17:28
  • You were probably hitting the PHP memory limit. If you go to Tools > Utilities > PHP Info in the control panel you should be able to see your current memory_limit setting. Ideally you probably want that value to be 64MB or greater - your host may be able to change that for you.
    – Dom Stubbs
    Jan 23 '13 at 18:01
1

Could you not just use something like this

{categories show="1|2|3|4|7|11|36|38"}
     <a href="{site_url}shopping/category/{category_url_title}">
    <div class="category-icons" rel="tooltip" title="{category_name}">
        <i class="icon-{category_name}"></i>
    </div>
     </a>
{/categories}

You can tell {categories} which categories you want to display. Then if you match image names with category names, you can use that to control, which icon class you call.

These parameters are available for the {categories} : backspace=, limit=, show=, show_group=,

3
  • Problem is that {site_url}shopping/ changes with each category so I need semi-lengthy conditionals or switchee. I added your suggestion of show="1|2|3|4|7|11|36|38" to the switchee tag and the page now loads. Thanks! Jan 23 '13 at 17:29
  • Glad at least part of it worked. But I should mention, even with the changing url, if you plan out the solution well, you can have the adjustments without switchee for example, if 'shopping, dining, nightlife' are parent categories, channels, or even just a field_type, you could build your url like: <a href="{site_url}/{parent}/category/{category_url_title}"> You didn't show your channel tag, so I didn't want to assume too much, but it can be done. Side note, you'd need a plugin to pull 'parent category' but not a channel short name or what we use frequently, a type_field. Jan 23 '13 at 17:46
  • You could also create custom category fields such as icon_name, site_section etc. That would help to reduce the need for the Switchee conditionals.
    – Dom Stubbs
    Jan 23 '13 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.