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.

DIsplay a list of entries with different field values

January 28, 2009 11:56pm

Subscribe [2]
  • #1 / Jan 28, 2009 11:56pm

    Kris Khaira

    38 posts

    I need to display a list of dates used in entries in a weblog, but the list cannot have a duplicate value. Right now I have this code where “wine_year” is a custom field:

    {exp:weblog:entries weblog="wine" limit="10" dynamic="off" orderby="wine_year" sort="desc"}
    <li><a href="/wine/year/{wine_year}">{wine_year}</a></li>
    {/exp:weblog:entries}

    Which displays the following:

    * 2003
    * 2003
    * 2002
    * 2002
    * 2002
    * 2001
    * 2001
    * 2001
    * 2001

    As you can see there are duplicate values. I would like to display the following:

    * 2003
    * 2002
    * 2001

    By the way, I want to use weblog:entries instead of hardcoding the years in a list because I don’t want to display values which are not used in the entries.

    How do I go about doing that? I’ve searched everywhere on the forum for an answer but I’m still cracking my brain!

  • #2 / Jan 29, 2009 12:33am

    Kris Khaira

    38 posts

    It’s ok I did it using exp:query! Thanks anyway!

    {exp:query sql="SELECT DISTINCT field_id_9 AS wine_year FROM exp_weblog_data ORDER BY wine_year DESC"}
    <li><a href="/wine/year/{wine_year}">{wine_year}</a></li>
    {/exp:query}
  • #3 / Jan 29, 2009 1:21am

    John Henry Donovan

    12339 posts

    Glad you got everything sorted. Please post again if you have any more issues.

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

ExpressionEngine News!

#eecms, #events, #releases