0

I'm currently developing a site and have run into a little bug, all but one category are working fine, the one that isn't working outputs all product entries from the whole site, any ideas why this would happen? My code is as follows:

{if segment_2 == "category"}

  {embed="site/_header" page_name="product_list"}

  {exp:channel:category_heading channel="products"}
      <h1>{category_name}</h1>
  {/exp:channel:category_heading}

  <div class="secondary-col">
    <ul class="categories">
    {exp:channel:categories show_empty="no" {if segment_1 == "cave"}category_group="3"{/if}{if segment_1 == "climb"}category_group="4"{/if}{if segment_1 == "camp"}category_group="5"{/if}{if segment_1 == "walk"}category_group="6"{/if}{if segment_1 == "clothing"}category_group="7"{/if}{if segment_1 == "accessories"}category_group="8"{/if}{if segment_1 == "brands"}category_group="2"{/if}}
        <a href="/{segment_1}/category/{category_url_title}">{category_name}</a>
    {/exp:channel:categories}
    </ul>
  </div>

  <div class="primary-col">

    {exp:channel:category_heading channel="products"}
        {if category_description}
            <div class="introduction"><p>{category_description}</p></div>
        {/if}
    {/exp:channel:category_heading}

    {exp:channel:entries channel="products" limit="50" paginate="bottom"}

    <ul class="product-list">
      {exp:store:product entry_id="{entry_id}"}
      <li>
        <article>
          <a href="{url_title_path='products'}">
            <h2>{title}</h2>
            <p>
              {if on_sale}
                <del>{regular_price}</del>
                {price}
                <span class="label label-success">Save {you_save} ({you_save_percent}%)</span>
              {if:else}
                {price}
              {/if}
            </p>
          </a>
        </article>
      </li>
      {/exp:store:product}

      {paginate}
        {pagination_links}
            <ul>
            {first_page}
              <li><a href="{pagination_url}" class="page-first">First Page</a></li>
            {/first_page}

            {previous_page}
              <li><a href="{pagination_url}" class="page-previous">Previous Page</a></li>
            {/previous_page}

            {page}
              <li><a href="{pagination_url}" class="page-{pagination_page_number} {if current_page}active{/if}">{pagination_page_number}</a></li>
            {/page}

            {next_page}
              <li><a href="{pagination_url}" class="page-next">Next Page</a></li>
            {/next_page}

            {last_page}
              <li><a href="{pagination_url}" class="page-last">Last Page</a></li>
            {/last_page}
          </ul>
        {/pagination_links}
      {/paginate}
    </ul>

    {/exp:channel:entries}

 </div> <!-- /primary-col-->
{/if}

You can view the problematic page here, it doesn't output the category title or anything, suggesting it can't find the category, but the category is being output from both the main navigational dropdowns and the secondary navigation on the left, there are 5 products assigned to this category too:

http://inglesport.rmdyapps.co.uk/cave/category/static-ropes

here's how a similar page looks:

http://inglesport.rmdyapps.co.uk/cave/category/rope-descenders

2

I'm guessing you're using the category in url feature, with the identifier of "category". I'd expect the issue is occurring due to no products assigned to that category, or that the category url is incorrect.

This URL does the same: http://inglesport.rmdyapps.co.uk/cave/category/blah

I'm assuming it can't find a valid category URL in the current URL, so the channel:entries tag is then pulling back all products (because it has no restriction).

If it were me, I'd approach it using Low Seg2Cat and then use the category parameter in the channel:entries call. That way you have full control and can utilise the no_results conditional and have {if "{last_segment_category_id}" == ""} to trap invalid category URLs.

| improve this answer | |
  • Turns out it was because we had the category static-ropes in two category parents, when I delete one of them the other works. I'm assuming you can't have the same name for a category in two groups :(! – Nick Sep 13 '13 at 16:06
  • Yes you can have duplicate category URLs, but you risk exactly what you've encountered. One way to resolve would be to specify the category group used in the channel:entries tag using category_group parameter. But if you've split your products into different groups, you'll want this template to cover all the groups, so doesn't help you. – Peter Lewis Sep 13 '13 at 16:17

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.