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.

50 state categories implementation

September 17, 2007 3:10pm

Subscribe [2]
  • #1 / Sep 17, 2007 3:10pm

    JCI

    144 posts

    I have a weblog entitled “States” with 50 categories assigned to it, 1 for each state.

    An editor will post a short blog entry and then select the state/category it corresponds to. 

    How can I implement the template(s) in such a way, so that I have 1 “master” State template.  And all the site user does is select a state from a 50 state jump menu (preferably) which passes that state/category ID as a variable to the “master” State template somehow, thus displaying only that states entries.

    I really just dont want to have 50 templates for each state.

    What is the best way to implement this?

  • #2 / Sep 17, 2007 4:17pm

    grantmx

    1439 posts

    This should be moved to the “How To” forum, but I would probably do something like this.

    Place this javascript in your <head></head>

    <!--
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
    }
    //-->

    Then this would be your jump menu that uses the script and the Category Archive tag:

    <form name="form" id="form">
      <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
    
    {exp:weblog:category_archive weblog="your_weblog" style="linear"}
            <option value="{path=SITE_INDEX}">{category_name}</option>
    {/exp:weblog:category_archive}
    
      </select>
    </form>

    Then to display the state info you could use this:

    {exp:weblog:category_archive weblog="{your_weblog}" show="11" style="linear"}
    
    {categories}
    <h1>{category_name}</h1>
    {if category_description}{category_description}{/if}
    
    
    
    {exp:weblog:entries weblog="{your_weblog}" orderby="date" sort="asc" category="11"} 
    
    {body}
    
    {/exp:weblog:entries}
    {/categories}
    
    {/exp:weblog:category_archive}

    The show=“11” parameter is for the corresponding State category id.  You’ll probably have to create {if} conditionals or Global Conditioal Variables in this template for each State to display the state data.

    If I’m not 100% on the conditionals part somebody will correct me.

  • #3 / Sep 18, 2007 11:58am

    JCI

    144 posts

    thanks for your help..

    everything is working great except the last concept.

    instead of copying the same piece of code 50 times and using conditionals for each state/category, is there no way to pull that from the URL and then use that in my parameters..

    example.. something like:

    {.... show={segment_3}}

    i know segment_3 will equate to CXX for example, but there has go to be a way to get the ‘C’ out of there.. or pull in the cat_id from the jump menu selection.

  • #4 / Sep 18, 2007 2:09pm

    grantmx

    1439 posts

    Hmmmm…

    Maybe somehow if you used {permalink=...} in the jump menu that would pass the entry id, insead of {path=site_index}.

    Try that.

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

ExpressionEngine News!

#eecms, #events, #releases