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.

dynamic sort

July 05, 2010 3:17pm

Subscribe [4]
  • #1 / Jul 05, 2010 3:17pm

    Eastwood Design

    605 posts

    I have a list of entries that include the entry date and a category name.

    I want to be able to filter the weblog listing either by date OR by category.  Date is working fine but how do I sort by category name?

    <form method="post" action="{path="site/Selections_Archive2"}">
              <h4>Filter your results:  </h4>
    <p>            <select name="orderby"><br />
                    <option value="title">Sort By:</option><br />
                    <option value="category">Track</option><br />
                    <option value="date">Race Date</option></p>
    
    <p>              <br />
                  </select><br />
                <br />
                  <select name="sort"><br />
                    <option value="asc">Order:</option><br />
                    <option value="asc">Ascending</option><br />
                    <option value="desc">Descending</option><br />
                  </select><br />
                <br />
                  <input type="submit" value="Go!" /><br />
                <br />
             <br />
            </form>

    {exp:weblog:entries weblog="sheets" orderby="date" sort="desc" limit="99" 
    show_future_entries="no" show_expired="yes" rdf="off" switch="row1|row2" 
    dynamic_parameters="category|orderby|limit|sort|"}
    <div class="{switch='row1|row2'}">
    <table width="470" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="172" align="left" valign="middle">{entry_date format='%l %F %d - %Y'}</td>
        <td width="171" align="left" valign="middle"> {categories} {category_name}{/categories}</td>
        <td width="127" align="left" valign="middle"><a href="http://{Selections}">DOWNLOAD</a></td>
      </tr>
    </table>
     </div>
    <!--end row12-->{/exp:weblog:entries}
  • #2 / Jul 05, 2010 5:18pm

    Ingmar

    29245 posts

    You will have to provide a category_id, like so:

    {exp:weblog:entries ... category="2" ...}

    Use the {exp:weblog:categories} tag to show a list of available categories.

  • #3 / Jul 05, 2010 8:33pm

    Eastwood Design

    605 posts

    I actually don’t want to display a list of available categories in the filter “order by” drop down.  I just want to resort the weblog entries by category or date

  • #4 / Jul 05, 2010 8:57pm

    Brandon Jones

    5500 posts

    To clarify, you want the weblog tag to return entries sorted by the name of each entry’s category?

  • #5 / Jul 05, 2010 9:07pm

    Eastwood Design

    605 posts

    yes that is the objective.  to refine the list by Category name alphabetically.

  • #6 / Jul 06, 2010 5:55am

    John Henry Donovan

    12339 posts

    Eastwood Design,

    Remove the orderby= parameter. Also remove the switch= as no such parameter exists.
    See if that works for you. Specifically having the orderby= parameter in there overrides the dynamic nature of what you are trying to do.

    {exp:weblog:entries weblog="sheets" sort="desc" limit="99" 
    show_future_entries="no" show_expired="yes" rdf="off" dynamic_parameters="category|orderby|limit|sort|"}
  • #7 / Jul 06, 2010 9:39am

    Eastwood Design

    605 posts

    not sure why I would remove my switch=‘row1|row2’  that controls my results styling.  I did remove orderby=“category” but it will still only refine the date, not by category name.

    When I select:

    <option value="category">Track</option>

    I want to refine the entries to be ordered by category name. is that option value correct?

    <div align="right"><form method="post" action="{path="site/Selections_Archive2"}">
              <h4>Filter your results:  </h4>
    <p>            <select name="orderby"><br />
                    <option value="title">Sort By:</option><br />
                    <option value="category">Track</option><br />
                    <option value="date">Race Date</option></p>
    
    <p>              </select><br />
                <br />
                  <select name="sort"><br />
                    <option value="asc">Order:</option><br />
                    <option value="asc">Ascending</option><br />
                    <option value="desc">Descending</option><br />
                  </select><br />
                  <input type="submit" value="Go!" /><br />
                     </form></div><h1>Selections Archive</h1></p>
    
    <p>{exp:weblog:entries weblog="sheets" orderby="category" category="7|8|9|10|11|12|13|14|15|16" sort="desc" limit="99" show_future_entries="no" show_expired="yes" rdf="off" switch="row1|row2" dynamic_parameters="orderby|category|limit|sort|"}<br />
    <div class="{switch='row1|row2'}"><br />
    <table width="470" border="0" cellspacing="0" cellpadding="0"><br />
      <tr><br />
        <td width="172" align="left" valign="middle">{entry_date format='%l %F %d - %Y'}</td><br />
        <td width="171" align="left" valign="middle"> {categories} {category_name}{/categories}</td><br />
        <td width="127" align="left" valign="middle"><a href="http://{Selections}">DOWNLOAD</a></td><br />
      </tr><br />
    </table><br />
     </div><br />
    {/exp:weblog:entries}

  • #8 / Jul 06, 2010 10:24am

    Eastwood Design

    605 posts

    I ended up using:

    <form method="post" action="{path="site/Selections_Archive"}">
    <select name="category">
         <option value="#">Choose Track</option>
    <option value="7|8|9|10|11|12|13|14|15|16" >All Tracks</option>
    {exp:weblog:categories weblog="sheets" style="nested"  show_empty="no"}
    <option value='{category_id}'>{category_name}</option>
    {/exp:weblog:categories}     
    
                  </select>
                  <input type="submit" value="Go!" />
                
             
            </form>

    for some reason

    <option value="all" >All Tracks</option>

    didn’t work to go back to displaying all entries, I had to hardcode in the cat id’s.  Would prefer if it would use the “all” value so when new categories are added it dynamically is updated

  • #9 / Jul 06, 2010 6:46pm

    Brandon Jones

    5500 posts

    category="all"

    isn’t really a valid parameter. Have you tried submitting ‘category’ with the value “” (blank)?

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

ExpressionEngine News!

#eecms, #events, #releases