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.

Check if a categorie is checked

November 01, 2011 6:46pm

Subscribe [2]
  • #1 / Nov 01, 2011 6:46pm

    Guido Neele

    8 posts

    Hi,

    I would like to create a list with checked and unchecked categories. Something like ...

    {exp:channel:categories channel="channel_name" style="nested" id="list-id"}
      if category === checked
        <a class="checked">{category_name}</a>
      else
        <a class="unchecked">{category_name}</a>
    {/exp:channel:categories}

    or

    {categories}
      if category === checked
        <a class="checked">{category_name}</a>
      else
        <a class="unchecked">{category_name}</a>
    {/categories}

    Is this possible?

  • #2 / Nov 02, 2011 5:52am

    Guido Neele

    8 posts

    Ok solved it by writing a plugin

    <?php
    if (!defined('BASEPATH')) exit('No direct script access allowed');
    
    class Is_checked {
            
        var $return_data = "";
    
        function __construct() {
    
            $this->EE =& get_instance();
            $entry_id = $this->EE->TMPL->fetch_param("entry_id");
            $cat_id = $this->EE->TMPL->fetch_param("category_id");
            
            $this->EE->db->where("entry_id", $entry_id);
            $this->EE->db->where("cat_id", $cat_id);
            $results = $this->EE->db->get("exp_category_posts");
    
            if ($results->num_rows() == 0) {
                $this->return_data = 0;
            }
            else {
                $this->return_data = 1;
            }
     
        }
        
    }
    
    /* End of file pi.is_checked.php */ 
    /* Location: ./system/expressionengine/third_party/is_checked/pi.is_checked.php */

    Code in template now looks like this:

    {exp:channel:categories channel="analyzers" style="nested" id="list-application-fields"}                    
       {if {exp:is_checked category_id="{category_id}" entry_id="{entry_id}"} == 1}
          <a href="http://{path=SITE_INDEX}class=supported">{category_name}</a>
       {if:else}
          <a href="http://{path=SITE_INDEX}class=unsupported">{category_name}</a>
       {/if}
    {/exp:channel:categories}
  • #3 / Nov 02, 2011 10:14am

    Sue Crocker

    26054 posts

    Glad you found an add-on to accomplish this. Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases