1

I don't seem to be able to use ExpressionEngine's native {exp:channel:category_heading} feature in combination with GWcode Categories.

I would like to display a simple category results page which displays all entries within a particular category, with the category name at the top as a page header. There will also be a list of all the categories in the sidebar (which I'm using GWcode for).

My code, simplified:

<!--Page heading-->      
{exp:channel:category_heading}
    <h2>{category_name}</h2>
{/exp:channel:category_heading}


<!--List of all the categories-->
<ul class="tags">
    {exp:gwcode_categories channel="project|miscellany" entry_count="yes" orderby="entry_count|cat_name" sort="desc" style="linear"}
    <li>{cat_name}</li>
    {/exp:gwcode_categories}
</ul>


<!--Results of selected category-->
{exp:channel:entries channel="project"}
    <img src="{project_thumbnail}" />
    <h2>{title}</h2>
{/exp:channel:entries}

The only bit that doesn't work is the page heading. Does anyone know why this might be?

Thanks.

1

That's one of the limitations of native category handling in EE. You can grab it with some PHP but even easier is to use Low Seg2Cat which is to remedy this type of case.

You can simple use {segment_n_category_name} to output the category name from the segment in the URL where it is displayed. So if you have a URL such as:

mysite.com/products/category

You can then output the category heading with:

<h2>{segment_2_category_name}</h2>

It is certainly very useful when working within the limitations of the native EE category handling.

EDIT: Updated to show an alternative method using the Query Module.

{exp:query sql="SELECT cat_name FROM exp_categories WHERE cat_url_title = '{segment_3}'"}
    {exp:channel:category_heading}

        <h2>{category_name}</h2>

    {/exp:channel:category_heading}
{/exp:query} 

Something like that should work if you didn't want to use Seg2Cat specifically. Just be sure to swap out {segment_3} with whatever segment variable contains your category URL title.

| improve this answer | |
  • Hi @Ian. Thanks for this – it works well. It is a shame there isn't a way to do it without an add-on though. – Sam Baldwin Apr 22 '13 at 12:17
  • 1
    Technically you can. I'm not entirely sure on the use case but you could use the Query Module to run the query directly. I've updated my post to add this example. The query should work but I've not tested it in templates. – Ian Apr 22 '13 at 16:44

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.