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.

Stacking multiple categories with dynamic parameters

October 31, 2011 6:17am

Subscribe [2]
  • #1 / Oct 31, 2011 6:17am

    kachunchau

    14 posts

    I’m trying to filter multiple categories using dynamic parameters but looking at this archive thread http://ellislab.com/forums/viewthread/105576/#531808 it doesn’t seen possible.

    Does anyone have a solution for this?

    And here’s the code I’ve been using.

    {exp:channel:entries channel="products" dynamic_parameters="category"}
    
    <div class="product">
    <h2>{title}</h2>
    <p>{product_description}<br />
    <ul><br />
    <li>{product_price}</li><br />
    <li>{product_lift_height}</li><br />
    <li>{product_fuel}</li><br />
    <li>{product_transmission}</li><br />
    <li>{product_doors}</li><br />
    <li>{product_year}M</li><br />
    <li>{product_capacity}</li><br />
    </ul><br />
    </div></p>
    
    <p>{/exp:channel:entries}</p>
    
    <p><form method="post" action="{path='site/index'}"><br />
        <select name="category"><br />
     <option value="">-- Manufacturer --</option><br />
            {exp:child_categories parent="3" child_categories_sort_direction="asc" show_empty="yes"}<br />
     {child_category_start}<br />
     <option value="{child_category_id}">{child_category_name}</option><br />
     {child_category_end}<br />
     {/exp:child_categories}<br />
        </select><br />
        <br />
        <select name="category"><br />
     <option value="">-- Model --</option><br />
            {exp:child_categories parent="2" child_categories_sort_direction="asc" show_empty="yes"}<br />
     {child_category_start}<br />
     <option value="{child_category_id}">{child_category_name}</option><br />
     {child_category_end}<br />
     {/exp:child_categories}<br />
        </select><br />
        <input type="submit" value="Go!" /><br />
    </form></p>
    
    <p><br />
    </body><br />
    </html>

    Thanks,
    Ka-Chun

  • #2 / Oct 31, 2011 11:28am

    Kevin Cupp

    791 posts

    Hi Ka-Chun,

    I think this post (http://ellislab.com/forums/viewthread/105576/#626053) is probably the best solution at the moment. You just set your PHP parsing mode to Input and then build the categories parameter string yourself from the $_POST data. Sorry there’s nothing better available at the moment, this is one of those special cases.

    Kevin

  • #3 / Oct 31, 2011 11:39am

    kachunchau

    14 posts

    Strangely that solution wasn’t working for me earlier but it’s working for me now. Thanks Kevin! By the way does this work with more than 2 categories?

  • #4 / Oct 31, 2011 11:47am

    Kevin Cupp

    791 posts

    Glad to hear it’s working. Yes the category parameter should work with as many categories as you need.

    Kevin

  • #5 / Oct 31, 2011 12:18pm

    kachunchau

    14 posts

    I’m getting a php error on the default page when I’m not filtering the entries, is there a way to fix this? Sorry for asking this but I’m not good with PHP.

    The code I’m using:

    <?php
    if (isset($_POST)){
        $cats = ' category="';
        $cats .= $_POST['manufacturer'] . "&" . $_POST['model'];
        $cats .= '" ';
    }
    else{
     $cats="";
    }
    ?> 
    
    <form method="post" action="{path='site'}">
    
        <select name="manufacturer">
     <option value="">-- Manufacturer --</option>
            {exp:child_categories parent="3" child_categories_sort_direction="asc" show_empty="yes"}
     {child_category_start}
     <option value="{child_category_id}">{child_category_name}</option>
     {child_category_end}
     {/exp:child_categories}
        </select>
        
        <select name="model">
     <option value="">-- Model --</option>
            {exp:child_categories parent="14" child_categories_sort_direction="asc" show_empty="yes"}
     {child_category_start}
     <option value="{child_category_id}">{child_category_name}</option>
     {child_category_end}
     {/exp:child_categories}
        </select>
    
        <input type="submit" value="Go!" />
    
    </form>
    
    {exp:channel:entries channel="products" dynamic="off" <?php echo $cats; ?>}
    
    <div class="product">
    <h2>{title}</h2>
    <p>{product_description}<br />
    <ul><br />
    <li>{product_price}</li><br />
    <li>{product_lift_height}</li><br />
    <li>{product_fuel}</li><br />
    <li>{product_transmission}</li><br />
    <li>{product_doors}</li><br />
    <li>{product_year}M</li><br />
    <li>{product_capacity}</li><br />
    </ul><br />
    </div></p>
    
    <p>{/exp:channel:entries}

    Thanks,
    Ka-Chun

    Edit: The error is an ‘Undefined index: manufacturer’ and for the model as well.

  • #6 / Oct 31, 2011 1:19pm

    Kevin Cupp

    791 posts

    To access POST data in templates now-a-days, I think you need to do this:

    $EE =& get_instance();
    $manufacturer = $EE->input->post('manufacturer');
    $model = $EE->input->post('model');

    Let me know how that works.

  • #7 / Oct 31, 2011 1:40pm

    kachunchau

    14 posts

    Is this what you’re suppose to do?

    <?php
    $EE =& get_instance();
    $manufacturer = $EE->input->post('manufacturer');
    $model = $EE->input->post('model');
    
    if (isset($_POST)){
        $cats = ' category="';
        $cats .= $_POST['manufacturer'] . "&" . $_POST['model'];
        $cats .= '" ';
    }
    else{
     $cats="";
    }
    ?>

    Sorry I’m not really helping with these PHP problems :red:

  • #8 / Oct 31, 2011 1:42pm

    Kevin Cupp

    791 posts

    That’s alright, I should have mentioned to replace your $_POST variables with the new ones you assigned at the top. So, this part of the code:

    $cats .= $_POST['manufacturer'] . "&" . $_POST['model'];

    ...should look like this:

    $cats .= $manufacturer . "&" . $model;

    Give that a try.

  • #9 / Oct 31, 2011 1:45pm

    kachunchau

    14 posts

    That did the job, thanks Kevin!

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

ExpressionEngine News!

#eecms, #events, #releases