ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem with channel:categories and active

August 21, 2014 8:09pm

Subscribe [3]
  • #1 / Aug 21, 2014 8:09pm

    raoulw

    4 posts

    I’m trying to create a list of all categories under each article with the categories for that article highlighted. Using EE 2.9. Code is:

    {exp:channel:categories channel="news" style="linear"}
      <a href="http://{path=%27news/index%27}" class="active">{category_name}</a>
    {/exp:channel:categories}

    Going by the docs this should work. What am i doing wrong?

  • #2 / Aug 22, 2014 8:29am

    Boyink!

    5011 posts

    I suspect you are using the wrong tag. To show what categories a specific entry is assigned to there is a looping {categories}{/categories} pair for the channel:entries tag.

    The channel:categories tag is a standalone tag not intended to be nested within a channel:entries tag - if that’s what you are doing.

  • #3 / Aug 24, 2014 7:32pm

    raoulw

    4 posts

    Hey thanks!

    I’m able to show the categories fine in the exp:channel:entries loop using {categories}{/categories} pair. But still nothing in the exp:channel:categories loop (which btw is below the entries loop).

    Could this be due to a setting somewhere or how I’ve setup the categories?

    A few other points:

    I’m using vanilla https://github.com/focuslabllc/ee-master-config for master config; and
    System is outside the web root; and
    This is my first ee site !

  • #4 / Aug 24, 2014 7:58pm

    Boyink!

    5011 posts

    Post your template code.

    And you’re getting no results at all?

  • #5 / Aug 24, 2014 8:09pm

    raoulw

    4 posts

    I’m getting results (all categories which is what I want), but the active tag is not working in exp:channel:categories.

    Here’s the code (from Robin- looks like it tripped a spam filter):

    {layout="site/.layout"} 
    
    {exp:channel:entries channel="news" limit="1"} 
    
    {layout:set name="title" value="{title}"} 
    
    {layout:set name="meta_desc" value="{exp:eehive_hacksaw cutoff=". " words=""}{news_body}{/exp:eehive_hacksaw}"} 
    
    {layout:set name="meta_cont" value="{categories backspace="2"}{category_name}, {/categories}"} 
    {layout:set name="js" value="<script src='/assets/scripts/libs/galleria.min.js'></script>"} 
    
    <div id="content"> 
     <div> 
      <section class="article-item"> <a href="http://{news_video:video}%22name=%22type%22&gt&lt/a&gt" class="article-item"><span class="video"></span></a> {/news_video} 
            {/if} 
    
           {if:else} 
            {if news_image:total_rows > 0} 
             {news_image} {news_image:image} {/news_image} 
            {/if} 
            {if news_video:total_rows > 0} 
             {news_video} <a href="http://{news_video:video}"><span class="video"></span></a> {/news_video} 
            {/if} 
           {/if} 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
    
      <div class="row"> 
       <div class="item sixcol"> 
        {news_body} <h4>Share</h4><p> Links to go here <br />
       </div> <br />
      </div> <br />
      </section> <br />
     </div> <br />
    </div> <br />
    {/exp:channel:entries} </p>
    
    <p><div id="content" class="inverse"> <br />
     <div> <br />
      <section class="article-tags"> <br />
      <div class="row"> <br />
       <div class="item twelvecol"> <br />
        </p><h4>Browse by</h4><p> <br />
        {exp:channel:categories channel="news" style="linear"} <br />
         <a href="http://{path=%27news/index%27}" class="active">{category_name}</a> {/exp:channel:categories} <br />
       </div> <br />
      </div> <br />
      </section> <br />
     </div> <br />
    </div> </p>
    
    <p><div id="content"> <br />
     <div> <section class="article-nav"> <br />
      <div class="row"> <div class="item sixcol"> <br />
       {exp:channel:next_entry channel="news"} <a href="http://{path=news/view}"><div class="previous">{next_entry->title}</div></a> {/exp:channel:next_entry} <br />
      </div> <br />
      <div class="item sixcol"> <br />
    {exp:channel:prev_entry channel="news"} <a href="http://{path=news/view}">_   <div class="next">{prev_entry->title}</div></a> <br />
    {/exp:channel:prev_entry} <br />
       </div> <br />
      </div> <br />
     </section> <br />
     </div> <br />
    </div>

  • #6 / Aug 24, 2014 8:10pm

    Boyink!

    5011 posts

    but the active tag is not working in exp:channel:categories.

    Tell me more about what you mean by this…what’s your desired result?

  • #7 / Aug 24, 2014 8:13pm

    raoulw

    4 posts

    What I’m after is a list of all categories, with the categories of the current post styled differently.

  • #8 / Aug 24, 2014 8:15pm

    Boyink!

    5011 posts

    Let me chew on that one - my gut reaction is “that just isn’t do-able” but sometimes an idea comes later.

    The channel:categories tag isn’t URL - aware, so it’s not going to “know” what entry is being displayed. It’s purpose is to show all categories in order so that you can choose one category and see what entries are in that one category.

    Likewise the categories looping pair isn’t intended to show all the categories, just the ones the currently-displayed entry has been assigned to.

  • #9 / Aug 25, 2014 11:41am

    Robin Sowell

    13255 posts

    Sorry about that spam filter- I posted the code for you, raoulw.  I don’t actually think you’re running into [this bug](https://support.ellislab.com/bugs/detail/20468/the-if-active-conditional-in-the-channel-categories-tag-may-fail-with-non-u), but since it is related to the active conditional, I’m dropping a ‘heads up’ on it as well.

  • #10 / Oct 07, 2014 1:11am

    raoulw

    4 posts

    Let me chew on that one - my gut reaction is “that just isn’t do-able” but sometimes an idea comes later.

    I had to persevere on this, and managed to get it working with this:

    {exp:channel:entries channel="news" limit="1"}
    
        <?php
        $this->EE =& get_instance();
        $id='{entry_id}';
        $res = $this->EE->db
                ->select('cat_name')
                ->from('exp_categories')
                ->join('exp_category_posts', 'exp_categories.cat_id = exp_category_posts.cat_id ')
                ->where('entry_id', $id)
                ->get()
                ->result_array();
        foreach ($res as $r) {
            $cats[] = $r['cat_name'];
        }
        ?>
    
            {exp:channel:categories channel="news" style="linear"}
    
                <?php
                $class="";
                $category_name = '{category_name}';
    
                foreach ($cats as $value) {
                    if ($value == $category_name) {
                        $class="active";
                    }
                } 
                ?>
                <a href="http://{path=%27news/index%27}" class="&lt?php echo $class?&gt">{category_name}</a>
    
            {/exp:channel:categories}
    
    {/exp:channel:entries}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases