We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Filter channel entry on detail page by State via dropdown list.

Development and Programming

MadMonk Interactive's avatar
MadMonk Interactive
6 posts
12 years ago
MadMonk Interactive's avatar MadMonk Interactive

So the question I have for you gentlemen is, how would I be able to sort a list of entries by their respective states dynamically?

I.e., without creating some 50+ templates for each US State\territory how can I have a single template that responds to whatever is piped to it..

I imagine it would look something like this:

Detail page:

{exp:channel:entries  dynamic_parameters="orderby|limit|sort"}

Prior page:

<form method="post" >
    <select name="Sort by:">
        <option value="">Select State</option>
        <option value="Nebraska">Nebraska</option>
        <option value="New Jersey">New Jersey</option>
        <option value="Nevada">Nevada</option> 
    </select>
    

    <input type="submit" value="Go!" />
</form>

And on the back end, I’d just have categories for each and every state right?

Definitely need some help from more knowledgeable EE people on this one.

Edit: Ok, I think I’ve found a solution but struggling to implement it correctly..

this is the plugin in question:http://devot-ee.com/add-ons/get-variable-to-segment-url-redirect

This is exactly the plugin I need to solve a project problem, but I cannot get it to work. It doesn’t do anything, and I’m sure its my own mistake but I cannot find any other helpful tidbits on this..

My form is:

<div id="sidebar">
                   <div class="aliance">
                      <h2>Clergy</h2>
                      <a href="http://{path=%27PCP/partner_congregations/%27}" class="more">Show All</a>
                      <ul>
                         <li><a href="http://alliance-marketing.madmonkdev2.com/index.php/PCP/congregation_list?State=21">Sort By</a>
                        <form  acti method="get">
                         <select name="State">
                           {exp:gwcode_categories cat_id="16" incl_self="no"}
                               <option value="{cat_id}">{cat_name}</option>
                         {/exp:gwcode_categories&#}
                           </select>
                          <input type="submit" value="Submit" />
                       </form>
                         </li> 
                      </ul>
                   </div>

Here’s the plugin code:

{exp:get_segment_redirect get_variable=“State” base_url=”/PCP/”}

The URL it should be redirecting but doesn’t:

[code]http://blahblahblah.com/index.php/PCP/congregation_list?State=17[/code]

I simply have to be overlooking something real simple here.. Because it’s not doing anything at all for me.

       
wildrock's avatar
wildrock
262 posts
12 years ago
wildrock's avatar wildrock

I do this a little differently. The following example is for a list of cities to pick from. The cities are all contained within a “Select Dropdown” fieldtype, and I’m using Mark Bowen’s Custom Drop Down Creator:

<form method="post" acti>
<select id="{exp:custom_drop_down:field_id field_name="City"}" name="{exp:custom_drop_down:field_id field_name="City"}">
{exp:custom_drop_down field_name="City" initial_value_value="no_city_picked" initial_value_option="Choose a City:"}<option value="{value}">{value}</option>
{/exp:custom_drop_down}
</select>


<input type="submit" value="submit" class="submit" />
</form>

(for whatever reason, the code snippet deletes out the rest of my form action. Use this for the rest of the form code: method=”post” action=”/index.php/template-group/search-results/”> )

All the Cities (or States in your case) then get entered into the custom field, using the “Select Dropdown” fieldtype, which allows you to manually populate the drop down.

Then I just capture the “post” value on the search-results page using a tad bit of PHP:

{exp:channel:entries channel="cityinfo" search:City="<?php echo $_POST['field_id_5']; ?>"}
City: <?php echo $_POST['field_id_5']; ?> -- other data: {custom-field-data}
{/exp:channel:entries}

The only other piece of info you need is what is the field_id of the field you are searching on. Go here in the CP:

Tools -> Data -> SQL Manager -> Manage Database Tables -> exp_channel_data (browse it)

In the exp_channel_data table, you’ll see the field_id numbers for all of the various fields you’ve setup. Find the one that has all of the state date you enter into your entries, and use that value in place of my “field_id_5”.

And you’re good to go.

       
Boyink!'s avatar
Boyink!
5,011 posts
12 years ago
Boyink!'s avatar Boyink!

If you are looking to display entries filtered by state then I can’t see why native EE categories and one template running dynamically wouldn’t work?

Some help: http://www.train-ee.com/courseware/free-tutorials/comments/working-with-categories/

       
MadMonk Interactive's avatar
MadMonk Interactive
6 posts
12 years ago
MadMonk Interactive's avatar MadMonk Interactive

Well, there were some mitigating factors involved but I basically figured it out with the help of a plugin + the developer behind the plugin. So we’re all good now, thanks guys!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.